Files
OmniRoute/src/types/sqljs.d.ts
Diego Rodrigues de Sa e Souza ec553dd9c0 fix(db): share sql.js preinit across callers, fix named-param bind (#6628, #6802) (#6899)
- preInitSqlJs() now memoizes an in-flight Promise (not just the resolved
  adapter) per filePath, so concurrent BATCH/STARTUP/HealthCheck/
  ProviderLimitsSync callers at boot share one full-file read+WASM decode
  instead of each independently reloading the whole database — the
  thundering-herd amplifier of the OOM condition #6632 already partly
  fixed, left un-implemented by the reporter's own proposed fix (#6628).

- sqljsAdapter's run/get/all now unwrap a lone named-parameter object
  (e.g. .all({ isActive: 1 }) for "WHERE is_active = @isActive", the same
  call shape getProviderConnections() already uses against better-sqlite3)
  before calling sql.js's stmt.bind(), expanding it to the @/:/$ sigil
  variants sql.js's own named-bind path requires. Previously the object
  was wrapped into an array and sql.js took the positional-bind path,
  throwing "Wrong API use : tried to bind a value of an unknown type
  ([object Object])." whenever the sql.js WASM fallback driver was active
  — exactly the error #6802 reported (misattributed to better-sqlite3).

Regression tests added to tests/unit/db-adapters/driverFactory.test.ts and
tests/unit/db-adapters/sqljsAdapter.test.ts, both proven RED against the
prior code and GREEN after the fix.
2026-07-11 11:21:37 -03:00

33 lines
794 B
TypeScript

declare module "sql.js" {
export interface SqlJsStatement {
bind(values: unknown[] | Record<string, unknown>): void;
step(): boolean;
getAsObject(): Record<string, unknown>;
free(): void;
}
export interface SqlJsResult {
columns: string[];
values: unknown[][];
}
export interface SqlJsDatabase {
prepare(sql: string): SqlJsStatement;
run(sql: string): void;
exec(sql: string): SqlJsResult[];
export(): Uint8Array;
close(): void;
getRowsModified(): number;
}
export interface SqlJsStatic {
Database: new (data?: Uint8Array) => SqlJsDatabase;
}
export interface SqlJsInitOptions {
locateFile?: (fileName: string) => string;
}
export default function initSqlJs(options?: SqlJsInitOptions): Promise<SqlJsStatic>;
}