|
@ -6,8 +6,9 @@ declare module 'absurd-sql/dist/indexeddb-backend'; |
|
|
import initSqlJs from '@jlongster/sql.js'; |
|
|
import initSqlJs from '@jlongster/sql.js'; |
|
|
import { SQLiteFS } from 'absurd-sql'; |
|
|
import { SQLiteFS } from 'absurd-sql'; |
|
|
import IndexedDBBackend from 'absurd-sql/dist/indexeddb-backend'; |
|
|
import IndexedDBBackend from 'absurd-sql/dist/indexeddb-backend'; |
|
|
|
|
|
|
|
|
import { runMigrations } from '../db-sql/migration'; |
|
|
import { runMigrations } from '../db-sql/migration'; |
|
|
import { QueryExecResult } from './migrationService'; |
|
|
import type { QueryExecResult } from '../interfaces/database'; |
|
|
|
|
|
|
|
|
interface SQLDatabase { |
|
|
interface SQLDatabase { |
|
|
exec: (sql: string, params?: any[]) => Promise<QueryExecResult[]>; |
|
|
exec: (sql: string, params?: any[]) => Promise<QueryExecResult[]>; |
|
@ -73,12 +74,13 @@ class DatabaseService { |
|
|
return this.db!.run(sql, params); |
|
|
return this.db!.run(sql, params); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Note that the resulting array may be empty if there are no results from the query
|
|
|
async query(sql: string, params: any[] = []): Promise<QueryExecResult[]> { |
|
|
async query(sql: string, params: any[] = []): Promise<QueryExecResult[]> { |
|
|
this.ensureInitialized(); |
|
|
this.ensureInitialized(); |
|
|
return this.db!.exec(sql, params); |
|
|
return this.db!.exec(sql, params); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async get(sql: string, params: any[] = []): Promise<any[] | undefined> { |
|
|
async getOneRow(sql: string, params: any[] = []): Promise<any[] | undefined> { |
|
|
this.ensureInitialized(); |
|
|
this.ensureInitialized(); |
|
|
const result = await this.db!.exec(sql, params); |
|
|
const result = await this.db!.exec(sql, params); |
|
|
return result[0]?.values[0]; |
|
|
return result[0]?.values[0]; |
|
|