| 15 | }); |
| 16 | |
| 17 | class FakeDatabase implements SQLiteDatabase { |
| 18 | readonly sessionColumns: Set<string>; |
| 19 | |
| 20 | constructor( |
| 21 | private version: number, |
| 22 | sessionColumns: string[], |
| 23 | ) { |
| 24 | this.sessionColumns = new Set(sessionColumns); |
| 25 | } |
| 26 | |
| 27 | exec(sql: string): void { |
| 28 | const match = sql.match(/ALTER TABLE sessions ADD COLUMN ([a-z_]+) /); |
| 29 | if (match?.[1]) { |
| 30 | this.sessionColumns.add(match[1]); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | prepare(sql: string): SQLiteStatement { |
| 35 | if (sql === "PRAGMA table_info(sessions)") { |
| 36 | return new FakeStatement(() => [...this.sessionColumns].map((name) => ({ name }))); |
| 37 | } |
| 38 | |
| 39 | throw new Error(`Unexpected SQL: ${sql}`); |
| 40 | } |
| 41 | |
| 42 | pragma(query: string, options?: { simple?: boolean }): unknown { |
| 43 | if (query === "user_version" && options?.simple) { |
| 44 | return this.version; |
| 45 | } |
| 46 | |
| 47 | const match = query.match(/^user_version = (\d+)$/); |
| 48 | if (match?.[1]) { |
| 49 | this.version = Number(match[1]); |
| 50 | return undefined; |
| 51 | } |
| 52 | |
| 53 | throw new Error(`Unexpected pragma: ${query}`); |
| 54 | } |
| 55 | |
| 56 | transaction<T>(fn: () => T): () => T { |
| 57 | return fn; |
| 58 | } |
| 59 | |
| 60 | close(): void {} |
| 61 | } |
| 62 | |
| 63 | class FakeStatement implements SQLiteStatement { |
| 64 | constructor(private readonly allFn: () => unknown[]) {} |
nothing calls this directly
no outgoing calls
no test coverage detected