UNPKG

@electric-sql/drivers

Version:

ElectricSQL database drivers.

15 lines (14 loc) 878 B
import { BindParams, Row } from '../util/types.js'; import type { Database as OriginalDatabase, Statement as OriginalStatement, Transaction, RunResult } from 'better-sqlite3'; export type { Transaction }; export interface Database extends Pick<OriginalDatabase, 'name' | 'inTransaction' | 'prepare' | 'transaction'> { exec(sql: string): this; } export type StatementBindParams<T = BindParams> = T extends any[] ? T : [T]; type BoundStatement<T extends unknown[], Result = unknown> = Omit<OriginalStatement<T, Result>, 'run' | 'get' | 'all' | 'iterate'> & { run: (...params: T) => RunResult; get: (...params: T) => Row | undefined; all: (...params: T) => Row[]; iterate: (...params: T) => IterableIterator<Row>; }; export type Statement<T extends BindParams = [], Result = unknown> = T extends any[] ? BoundStatement<T, Result> : BoundStatement<[T], Result>;