summaryrefslogtreecommitdiff
path: root/packages/idb-bridge/src/sqlite3-interface.ts
blob: 8668ef844e159ed27c7933f6650fb16f52a588fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
export type Sqlite3Database = {
  internalDbHandle: any;
  exec(sqlStr: string): void;
  prepare(stmtStr: string): Sqlite3Statement;
  close(): void;
};
export type Sqlite3Statement = {
  internalStatement: any;

  run(params?: BindParams): RunResult;
  getAll(params?: BindParams): ResultRow[];
  getFirst(params?: BindParams): ResultRow | undefined;
};

export interface RunResult {
  lastInsertRowid: number | bigint;
}

export type Sqlite3Value = string | Uint8Array | number | null | bigint;

export type BindParams = Record<string, Sqlite3Value | undefined>;
export type ResultRow = Record<string, Sqlite3Value>;

/**
 * Common interface that multiple sqlite3 bindings
 * (such as better-sqlite3 or qtart's sqlite3 bindings)
 * can adapt to.
 *
 * This does not expose full sqlite3 functionality, but just enough
 * to be used by our IndexedDB sqlite3 backend.
 */
export interface Sqlite3Interface {
  open(filename: string): Sqlite3Database;
}