MCPcopy Create free account
hub / github.com/CaviraOSS/PageLM / SQLiteDatabase

Class SQLiteDatabase

backend/src/utils/database/sqlite.ts:4–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2import path from 'path'
3
4class SQLiteDatabase {
5 private db: sqlite3.Database
6
7 constructor(dbPath: string) {
8 this.db = new sqlite3.Database(dbPath)
9 }
10
11 async run(sql: string, params: any[] = []): Promise<sqlite3.RunResult> {
12 return new Promise((resolve, reject) => {
13 this.db.run(sql, params, function (err) {
14 if (err) reject(err)
15 else resolve(this)
16 })
17 })
18 }
19
20 async get(sql: string, params: any[] = []): Promise<any> {
21 return new Promise((resolve, reject) => {
22 this.db.get(sql, params, (err, row) => {
23 if (err) reject(err)
24 else resolve(row)
25 })
26 })
27 }
28
29 async all(sql: string, params: any[] = []): Promise<any[]> {
30 return new Promise((resolve, reject) => {
31 this.db.all(sql, params, (err, rows) => {
32 if (err) reject(err)
33 else resolve(rows || [])
34 })
35 })
36 }
37
38 close(): Promise<void> {
39 return new Promise((resolve, reject) => {
40 this.db.close((err) => {
41 if (err) reject(err)
42 else resolve()
43 })
44 })
45 }
46}
47
48const dbPath = path.join(process.cwd(), 'storage', 'database.sqlite')
49export const sqlite = new SQLiteDatabase(dbPath)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected