db.d.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * db.ts - Cross-runtime SQLite compatibility layer
  3. *
  4. * Provides a unified Database export that works under both Bun (bun:sqlite)
  5. * and Node.js (better-sqlite3). The APIs are nearly identical — the main
  6. * difference is the import path.
  7. *
  8. * On macOS, Apple's system SQLite is compiled with SQLITE_OMIT_LOAD_EXTENSION,
  9. * which prevents loading native extensions like sqlite-vec. When running under
  10. * Bun we call Database.setCustomSQLite() to swap in Homebrew's full-featured
  11. * SQLite build before creating any database instances.
  12. */
  13. export declare const isBun: boolean;
  14. /**
  15. * Open a SQLite database. Works with both bun:sqlite and better-sqlite3.
  16. */
  17. export declare function openDatabase(path: string): Database;
  18. /**
  19. * Common subset of the Database interface used throughout QMD.
  20. */
  21. export interface Database {
  22. exec(sql: string): void;
  23. prepare(sql: string): Statement;
  24. loadExtension(path: string): void;
  25. close(): void;
  26. }
  27. export interface Statement {
  28. run(...params: any[]): {
  29. changes: number;
  30. lastInsertRowid: number | bigint;
  31. };
  32. get(...params: any[]): any;
  33. all(...params: any[]): any[];
  34. }
  35. /**
  36. * Load the sqlite-vec extension into a database.
  37. *
  38. * Throws with platform-specific fix instructions when the extension is
  39. * unavailable.
  40. */
  41. export declare function loadSqliteVec(db: Database): void;