| 12 | static db: DatabaseConnection | null = null; |
| 13 | |
| 14 | private static async createTables(db: DatabaseConnection) { |
| 15 | await db.exec( |
| 16 | `CREATE TABLE IF NOT EXISTS tokens_generated ( |
| 17 | id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 18 | model TEXT NOT NULL, |
| 19 | provider TEXT NOT NULL, |
| 20 | tokens_generated INTEGER NOT NULL, |
| 21 | tokens_prompt INTEGER NOT NULL DEFAULT 0, |
| 22 | timestamp DATETIME DEFAULT CURRENT_TIMESTAMP |
| 23 | )`, |
| 24 | ); |
| 25 | |
| 26 | // Add tokens_prompt column if it doesn't exist |
| 27 | const columnCheckResult = await db.all( |
| 28 | "PRAGMA table_info(tokens_generated);", |
| 29 | ); |
| 30 | const columnExists = columnCheckResult.some( |
| 31 | (col: any) => col.name === "tokens_prompt", |
| 32 | ); |
| 33 | if (!columnExists) { |
| 34 | await db.exec( |
| 35 | "ALTER TABLE tokens_generated ADD COLUMN tokens_prompt INTEGER NOT NULL DEFAULT 0;", |
| 36 | ); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | public static async logTokensGenerated( |
| 41 | model: string, |