Data storage (#3)

* feat: add prisma

* fix: generate prisma
This commit is contained in:
2025-06-23 19:04:01 +02:00
committed by GitHub
parent 5e5c090cd9
commit 30c67a308b
8 changed files with 189 additions and 12 deletions

44
utils/db.ts Normal file
View File

@@ -0,0 +1,44 @@
import { PrismaClient } from '@prisma/client';
declare global {
var prisma: PrismaClient | undefined;
}
const db = global.prisma || new PrismaClient();
if (process.env.NODE_ENV === 'development') {
global.prisma = db;
}
export const dbOperations = {
async saveAnthropicQuery({
question,
response,
success,
errorMessage,
tokensUsed
}: {
question: string;
response: string;
success: boolean;
errorMessage?: string;
tokensUsed?: number;
}) {
try {
return await db.anthropicQuery.create({
data: {
question,
response,
success,
errorMessage,
tokensUsed
}
});
} catch (error) {
console.error('Failed to save query:', error);
return null;
}
}
};
export { db };