| 36 | * 基于 better-sqlite3 的 DatabaseAdapter 实现 |
| 37 | */ |
| 38 | export class BetterSqliteAdapter implements DatabaseAdapter { |
| 39 | readonly?: boolean |
| 40 | |
| 41 | constructor(private db: Database.Database) { |
| 42 | this.readonly = db.readonly |
| 43 | } |
| 44 | |
| 45 | exec(sql: string): void { |
| 46 | this.db.exec(sql) |
| 47 | } |
| 48 | |
| 49 | prepare(sql: string): PreparedStatement { |
| 50 | return new BetterSqlitePreparedStatement(this.db.prepare(sql)) |
| 51 | } |
| 52 | |
| 53 | transaction<T>(fn: () => T): T { |
| 54 | return this.db.transaction(fn)() |
| 55 | } |
| 56 | |
| 57 | pragma(pragma: string): unknown { |
| 58 | return this.db.pragma(pragma) |
| 59 | } |
| 60 | |
| 61 | close(): void { |
| 62 | this.db.close() |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * 从文件路径打开数据库并返回适配器 |
nothing calls this directly
no outgoing calls
no test coverage detected