@crvouga/sqlite-mem 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/AGENTS.md +154 -0
  2. package/COMPATIBILITY-AUDIT.md +7 -9
  3. package/COMPATIBILITY.md +5 -4
  4. package/README.md +166 -16
  5. package/compat/coverage.json +797 -512
  6. package/compat/requirements.json +1 -1
  7. package/dist/api/database.d.ts +97 -12
  8. package/dist/api/statement.d.ts +65 -18
  9. package/dist/ast/nodes.d.ts +11 -2
  10. package/dist/constraints/check.d.ts +5 -6
  11. package/dist/errors/index.d.ts +36 -3
  12. package/dist/executor/attach.d.ts +3 -4
  13. package/dist/executor/ddl.d.ts +3 -4
  14. package/dist/executor/dml.d.ts +4 -4
  15. package/dist/executor/env.d.ts +9 -11
  16. package/dist/executor/execute.d.ts +3 -4
  17. package/dist/executor/pragma.d.ts +3 -4
  18. package/dist/executor/result.d.ts +10 -6
  19. package/dist/executor/select.d.ts +4 -5
  20. package/dist/executor/simple-select.d.ts +3 -4
  21. package/dist/executor/triggers.d.ts +6 -7
  22. package/dist/executor/vtable.d.ts +5 -6
  23. package/dist/expressions/context.d.ts +5 -5
  24. package/dist/expressions/equals.d.ts +3 -0
  25. package/dist/expressions/eval.d.ts +9 -4
  26. package/dist/expressions/index.d.ts +3 -4
  27. package/dist/expressions/like.d.ts +13 -3
  28. package/dist/functions/aggregate.d.ts +1 -2
  29. package/dist/functions/datetime.d.ts +1 -2
  30. package/dist/functions/extensions.d.ts +1 -2
  31. package/dist/functions/index.d.ts +8 -9
  32. package/dist/functions/json.d.ts +3 -4
  33. package/dist/functions/math.d.ts +1 -2
  34. package/dist/functions/registry.d.ts +5 -6
  35. package/dist/functions/scalar.d.ts +2 -3
  36. package/dist/functions/table-valued.d.ts +3 -4
  37. package/dist/functions/window.d.ts +1 -2
  38. package/dist/index.d.ts +27 -12
  39. package/dist/index.js +986 -203
  40. package/dist/index.js.map +4 -4
  41. package/dist/indexes/index.d.ts +17 -4
  42. package/dist/json/index.d.ts +7 -8
  43. package/dist/json/jsonb.d.ts +1 -2
  44. package/dist/json/ops.d.ts +8 -3
  45. package/dist/json/parse.d.ts +2 -3
  46. package/dist/json/path.d.ts +1 -2
  47. package/dist/json/stringify.d.ts +1 -2
  48. package/dist/json/tvf.d.ts +1 -2
  49. package/dist/json/types.d.ts +0 -1
  50. package/dist/lexer/tokenize.d.ts +7 -1
  51. package/dist/parser/index.d.ts +11 -5
  52. package/dist/parser/parser.d.ts +3 -3
  53. package/dist/planner/access.d.ts +13 -6
  54. package/dist/planner/index.d.ts +1 -2
  55. package/dist/runtime/clock.d.ts +8 -2
  56. package/dist/runtime/index.d.ts +3 -4
  57. package/dist/runtime/options.d.ts +4 -6
  58. package/dist/runtime/prng.d.ts +12 -1
  59. package/dist/schema/catalog.d.ts +2 -3
  60. package/dist/serialization/codec.d.ts +17 -2
  61. package/dist/serialization/index.d.ts +1 -2
  62. package/dist/storage/database-state.d.ts +16 -8
  63. package/dist/storage/index.d.ts +6 -7
  64. package/dist/storage/row.d.ts +1 -2
  65. package/dist/storage/table.d.ts +8 -4
  66. package/dist/transactions/manager.d.ts +2 -3
  67. package/dist/types/collation.d.ts +1 -2
  68. package/dist/types/strict.d.ts +6 -0
  69. package/dist/types/value.d.ts +30 -2
  70. package/dist/unstable.d.ts +20 -0
  71. package/dist/unstable.js +8734 -0
  72. package/dist/unstable.js.map +7 -0
  73. package/dist/vtable/fts/options.d.ts +0 -1
  74. package/dist/vtable/fts/porter.d.ts +0 -1
  75. package/dist/vtable/fts/query.d.ts +0 -1
  76. package/dist/vtable/fts/table.d.ts +5 -6
  77. package/dist/vtable/fts/tokenize.d.ts +1 -2
  78. package/dist/vtable/fts5.d.ts +1 -2
  79. package/dist/vtable/index.d.ts +2 -3
  80. package/dist/vtable/modules.d.ts +2 -3
  81. package/package.json +19 -10
  82. package/compat/gate-report.json +0 -424
  83. package/dist/api/database.d.ts.map +0 -1
  84. package/dist/api/statement.d.ts.map +0 -1
  85. package/dist/ast/nodes.d.ts.map +0 -1
  86. package/dist/constraints/check.d.ts.map +0 -1
  87. package/dist/errors/index.d.ts.map +0 -1
  88. package/dist/executor/attach.d.ts.map +0 -1
  89. package/dist/executor/ddl.d.ts.map +0 -1
  90. package/dist/executor/dml.d.ts.map +0 -1
  91. package/dist/executor/env.d.ts.map +0 -1
  92. package/dist/executor/execute.d.ts.map +0 -1
  93. package/dist/executor/pragma.d.ts.map +0 -1
  94. package/dist/executor/result.d.ts.map +0 -1
  95. package/dist/executor/select.d.ts.map +0 -1
  96. package/dist/executor/simple-select.d.ts.map +0 -1
  97. package/dist/executor/triggers.d.ts.map +0 -1
  98. package/dist/executor/vtable.d.ts.map +0 -1
  99. package/dist/expressions/context.d.ts.map +0 -1
  100. package/dist/expressions/eval.d.ts.map +0 -1
  101. package/dist/expressions/index.d.ts.map +0 -1
  102. package/dist/expressions/like.d.ts.map +0 -1
  103. package/dist/functions/aggregate.d.ts.map +0 -1
  104. package/dist/functions/datetime.d.ts.map +0 -1
  105. package/dist/functions/extensions.d.ts.map +0 -1
  106. package/dist/functions/index.d.ts.map +0 -1
  107. package/dist/functions/json.d.ts.map +0 -1
  108. package/dist/functions/math.d.ts.map +0 -1
  109. package/dist/functions/registry.d.ts.map +0 -1
  110. package/dist/functions/scalar.d.ts.map +0 -1
  111. package/dist/functions/table-valued.d.ts.map +0 -1
  112. package/dist/functions/window.d.ts.map +0 -1
  113. package/dist/index.d.ts.map +0 -1
  114. package/dist/indexes/index.d.ts.map +0 -1
  115. package/dist/json/index.d.ts.map +0 -1
  116. package/dist/json/jsonb.d.ts.map +0 -1
  117. package/dist/json/ops.d.ts.map +0 -1
  118. package/dist/json/parse.d.ts.map +0 -1
  119. package/dist/json/path.d.ts.map +0 -1
  120. package/dist/json/stringify.d.ts.map +0 -1
  121. package/dist/json/tvf.d.ts.map +0 -1
  122. package/dist/json/types.d.ts.map +0 -1
  123. package/dist/lexer/tokenize.d.ts.map +0 -1
  124. package/dist/parser/index.d.ts.map +0 -1
  125. package/dist/parser/parser.d.ts.map +0 -1
  126. package/dist/planner/access.d.ts.map +0 -1
  127. package/dist/planner/index.d.ts.map +0 -1
  128. package/dist/runtime/clock.d.ts.map +0 -1
  129. package/dist/runtime/index.d.ts.map +0 -1
  130. package/dist/runtime/options.d.ts.map +0 -1
  131. package/dist/runtime/prng.d.ts.map +0 -1
  132. package/dist/schema/catalog.d.ts.map +0 -1
  133. package/dist/serialization/codec.d.ts.map +0 -1
  134. package/dist/serialization/index.d.ts.map +0 -1
  135. package/dist/storage/database-state.d.ts.map +0 -1
  136. package/dist/storage/index.d.ts.map +0 -1
  137. package/dist/storage/row.d.ts.map +0 -1
  138. package/dist/storage/table.d.ts.map +0 -1
  139. package/dist/transactions/manager.d.ts.map +0 -1
  140. package/dist/types/collation.d.ts.map +0 -1
  141. package/dist/types/value.d.ts.map +0 -1
  142. package/dist/vtable/fts/options.d.ts.map +0 -1
  143. package/dist/vtable/fts/porter.d.ts.map +0 -1
  144. package/dist/vtable/fts/query.d.ts.map +0 -1
  145. package/dist/vtable/fts/table.d.ts.map +0 -1
  146. package/dist/vtable/fts/tokenize.d.ts.map +0 -1
  147. package/dist/vtable/fts5.d.ts.map +0 -1
  148. package/dist/vtable/index.d.ts.map +0 -1
  149. package/dist/vtable/modules.d.ts.map +0 -1
@@ -1,5 +1,5 @@
1
1
  {
2
- "generatedAt": "2026-08-17T20:01:39.525Z",
2
+ "generatedAt": "2026-08-18T15:54:12.225Z",
3
3
  "sourceUrl": "https://www.sqlite.org/requirements.html",
4
4
  "count": 3487,
5
5
  "requirements": [
@@ -1,26 +1,111 @@
1
- import { type Clock, type DatabaseOptions, Prng } from "../runtime/index.ts";
2
- import { DatabaseState } from "../storage/database-state.ts";
3
- import { TransactionManager } from "../transactions/manager.ts";
4
- import { Statement } from "./statement.ts";
1
+ import { type DatabaseOptions } from "../runtime/index.js";
2
+ import type { BindValue, QueryRow } from "../types/value.js";
3
+ import { Statement } from "./statement.js";
4
+ /**
5
+ * Pure TypeScript in-memory SQLite database.
6
+ *
7
+ * Deterministic by default: `random()` / `randomblob()` use a seeded PRNG
8
+ * (`seed` defaults to `1`) and `date('now')` / friends use a fixed clock
9
+ * (`2000-01-01T00:00:00.000Z`). There is no filesystem or WASM.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { Database } from "@crvouga/sqlite-mem";
14
+ *
15
+ * const db = new Database();
16
+ * db.exec("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT NOT NULL)");
17
+ * db.prepare("INSERT INTO users (name) VALUES (?)").run("Alice");
18
+ * const users = db.query<{ id: number; name: string }>("SELECT * FROM users");
19
+ * ```
20
+ */
5
21
  export declare class Database {
6
- readonly state: DatabaseState;
22
+ /** Seed used to construct the PRNG. */
7
23
  readonly seed: number | bigint;
8
- readonly prng: Prng;
9
- now: Clock;
10
- readonly transactions: TransactionManager;
11
24
  private closed;
12
25
  private transactionSequence;
26
+ /** Depth of active {@link transaction} callbacks (not SQL BEGIN). */
27
+ private apiTransactionDepth;
28
+ /**
29
+ * Create an empty in-memory database.
30
+ *
31
+ * @param options - Determinism knobs. See {@link DatabaseOptions}.
32
+ */
13
33
  constructor(options?: DatabaseOptions);
14
- exec(sql: string, params?: unknown[]): void;
15
- query<T = Record<string, unknown>>(sql: string, params?: unknown[]): T[];
34
+ /**
35
+ * Execute SQL for its side effects (DDL/DML). Multiple statements are allowed.
36
+ *
37
+ * Does not accept bind parameters — use {@link prepare} or {@link query}.
38
+ *
39
+ * @param sql - SQL to run (semicolon-separated statements are ok).
40
+ * @throws {SqliteError} If the database is closed, extra arguments are passed, or the SQL fails.
41
+ */
42
+ exec(sql: string): void;
43
+ /**
44
+ * Execute a single-statement query and return all rows as objects keyed by column name.
45
+ *
46
+ * @typeParam T - Row shape. Defaults to {@link QueryRow}.
47
+ * @param sql - A single SQL statement (trailing `;` is fine).
48
+ * @param params - Bound parameters for `?` / `:name` placeholders.
49
+ * @returns All result rows.
50
+ * @throws {SqliteError} If the database is closed, `sql` is not a single statement, or execution fails.
51
+ */
52
+ query<T = QueryRow>(sql: string, params?: readonly BindValue[]): T[];
53
+ /**
54
+ * Compile a single SQL statement into a reusable {@link Statement}.
55
+ *
56
+ * @param sql - A single SQL statement (trailing `;` is fine). Multi-statement scripts are rejected.
57
+ * @throws {SqliteError} If the database is closed or `sql` cannot be prepared as one statement.
58
+ */
16
59
  prepare(sql: string): Statement;
60
+ /**
61
+ * Run `fn` inside a transaction. Commits on success; rolls back if `fn` throws.
62
+ *
63
+ * Nested calls use SAVEPOINTs so an inner failure does not abort the outer
64
+ * transaction. Calling {@link close} from inside `fn` throws `misuse`.
65
+ *
66
+ * @param fn - Work to run while the transaction is open.
67
+ * @returns The value returned by `fn`.
68
+ * @throws {SqliteError} If the database is closed. Re-throws whatever `fn` throws after rollback.
69
+ */
17
70
  transaction<T>(fn: () => T): T;
71
+ /**
72
+ * Serialize schema, rows, PRNG state, and clock into a custom snapshot blob.
73
+ *
74
+ * This is not a `.sqlite` file. Restore it with {@link restore}.
75
+ *
76
+ * @throws {SqliteError} If the database is closed.
77
+ */
18
78
  snapshot(): Uint8Array;
79
+ /**
80
+ * Replace this database's contents with a blob from {@link snapshot}.
81
+ *
82
+ * Restores PRNG state and the clock when the snapshot includes them (v2).
83
+ * Newer library versions can restore older snapshots; older libraries cannot
84
+ * restore newer format versions.
85
+ *
86
+ * @param snapshot - Bytes previously returned by {@link snapshot}.
87
+ * @throws {SqliteError} If the database is closed, a transaction is open, or the blob is invalid.
88
+ */
19
89
  restore(snapshot: Uint8Array): void;
90
+ /**
91
+ * Close the database. Further SQL throws {@link SqliteError}. Idempotent.
92
+ *
93
+ * Rolls back an open SQL transaction, if any. Throws if called from inside
94
+ * a {@link transaction} callback.
95
+ */
20
96
  close(): void;
97
+ /**
98
+ * Rows changed by the most recent INSERT / UPDATE / DELETE (SQLite `changes()`).
99
+ *
100
+ * @throws {SqliteError} If the database is closed.
101
+ */
21
102
  get changes(): number;
103
+ /**
104
+ * Rowid of the most recent INSERT (SQLite `last_insert_rowid()`).
105
+ *
106
+ * @throws {SqliteError} If the database is closed.
107
+ */
22
108
  get lastInsertRowid(): number | bigint;
23
- assertOpen(): void;
109
+ private prepareSingle;
24
110
  }
25
111
  export type { DatabaseOptions };
26
- //# sourceMappingURL=database.d.ts.map
@@ -1,27 +1,74 @@
1
- import type { Statement as AstStatement } from "../ast/nodes.ts";
2
- import { ExecutionEnv } from "../executor/env.ts";
3
- import type { ResultSet } from "../executor/result.ts";
4
- import type { Database } from "./database.ts";
1
+ import type { ResultSet } from "../executor/result.js";
2
+ import type { BindValue, QueryRow } from "../types/value.js";
3
+ /** Mutation counters returned by {@link Statement.run}. */
4
+ export interface RunResult {
5
+ /** Rows changed by this execution (SQLite `changes()`). */
6
+ changes: number;
7
+ /** Rowid of the most recent INSERT in this execution. */
8
+ lastInsertRowid: number | bigint;
9
+ }
10
+ /**
11
+ * Prepared SQL statement bound to a {@link Database}.
12
+ *
13
+ * Create with {@link Database.prepare}. Pass bind values as rest arguments to
14
+ * {@link run}, {@link all}, {@link get}, or {@link result} on each call
15
+ * (stateless — there is no sticky `bind()`).
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { Database } from "@crvouga/sqlite-mem";
20
+ *
21
+ * const db = new Database();
22
+ * db.exec("CREATE TABLE t (id INTEGER PRIMARY KEY, name TEXT)");
23
+ * const insert = db.prepare("INSERT INTO t (name) VALUES (?)");
24
+ * insert.run("Ada");
25
+ * const row = db.prepare("SELECT id, name FROM t WHERE id = ?").get<{ id: number; name: string }>(1);
26
+ * ```
27
+ */
5
28
  export declare class Statement {
6
29
  private readonly database;
7
30
  private readonly sql;
8
- private readonly statements;
9
- private bound;
10
31
  private namedPlan;
11
32
  private env;
12
- constructor(database: Database, sql: string, statements: AstStatement[]);
13
- bind(...params: unknown[]): Statement;
14
- run(...params: unknown[]): {
15
- changes: number;
16
- lastInsertRowid: number | bigint;
17
- };
18
- all<T>(...params: unknown[]): T[];
19
- /** Full result including column names (needed for empty result-set metadata). */
20
- result(...params: unknown[]): ResultSet;
21
- get<T>(...params: unknown[]): T | undefined;
33
+ private statements;
34
+ private schemaVersion;
35
+ private constructor();
36
+ /**
37
+ * Execute for side effects (INSERT / UPDATE / DELETE / DDL).
38
+ *
39
+ * @param params - Bind values for this call only.
40
+ * @returns Mutation counters for this execution.
41
+ * @throws {SqliteError} If the database is closed, the statement is empty, or execution fails.
42
+ */
43
+ run(...params: BindValue[]): RunResult;
44
+ /**
45
+ * Execute and return every result row as an object keyed by column name.
46
+ *
47
+ * @typeParam T - Row shape. Defaults to {@link QueryRow}.
48
+ * @param params - Bind values for this call only.
49
+ * @throws {SqliteError} If the database is closed, the statement is empty, or execution fails.
50
+ */
51
+ all<T = QueryRow>(...params: BindValue[]): T[];
52
+ /**
53
+ * Execute and return the full {@link ResultSet}, including column names.
54
+ *
55
+ * Use this when you need metadata for an empty result (column names with zero rows).
56
+ * {@link all} only returns row objects.
57
+ *
58
+ * @param params - Bind values for this call only.
59
+ * @throws {SqliteError} If the database is closed, the statement is empty, or execution fails.
60
+ */
61
+ result(...params: BindValue[]): ResultSet;
62
+ /**
63
+ * Execute and return the first row, or `undefined` if there are no rows.
64
+ *
65
+ * @typeParam T - Row shape. Defaults to {@link QueryRow}.
66
+ * @param params - Bind values for this call only.
67
+ * @throws {SqliteError} If the database is closed, the statement is empty, or execution fails.
68
+ */
69
+ get<T = QueryRow>(...params: BindValue[]): T | undefined;
22
70
  private execute;
23
71
  private obtainEnv;
72
+ private reprepareIfSchemaChanged;
24
73
  private bindNamed;
25
74
  }
26
- export declare function bindNamedParameters(env: ExecutionEnv, sql: string, params: readonly unknown[]): void;
27
- //# sourceMappingURL=statement.d.ts.map
@@ -1,6 +1,7 @@
1
- import type { SqlValue } from "../types/value.ts";
1
+ import type { SqlValue } from "../types/value.js";
2
2
  export type BinaryOp = "+" | "-" | "*" | "/" | "%" | "||" | "=" | "==" | "!=" | "<>" | "<" | "<=" | ">" | ">=" | "AND" | "OR" | "IS" | "IS NOT" | "IS DISTINCT FROM" | "IS NOT DISTINCT FROM" | "LIKE" | "NOT LIKE" | "GLOB" | "NOT GLOB" | "IN" | "NOT IN" | "MATCH" | "->" | "->>" | "&" | "|" | "<<" | ">>";
3
3
  export type UnaryOp = "+" | "-" | "~" | "NOT";
4
+ /** Parsed SQL expression AST (literals, operators, functions, subqueries, …). */
4
5
  export type Expr = LiteralExpr | NullExpr | ColumnRefExpr | UnaryExpr | BinaryExpr | BetweenExpr | InExpr | LikeExpr | FunctionExpr | AggregateExpr | WindowExpr | CaseExpr | CastExpr | ExistsExpr | SubqueryExpr | ParameterExpr | RowExpr | CollateExpr;
5
6
  export interface LiteralExpr {
6
7
  type: "literal";
@@ -78,6 +79,7 @@ export interface FrameSpec {
78
79
  type: "ROWS" | "RANGE" | "GROUPS";
79
80
  start: FrameBound;
80
81
  end: FrameBound;
82
+ exclude: "no_others" | "current_row" | "group" | "ties" | null;
81
83
  }
82
84
  export type FrameBound = {
83
85
  kind: "unbounded_preceding";
@@ -231,6 +233,7 @@ export interface InsertStmt {
231
233
  }
232
234
  export interface UpsertClause {
233
235
  targetColumns: string[] | null;
236
+ targetExprs: Expr[] | null;
234
237
  targetWhere: Expr | null;
235
238
  action: "nothing" | {
236
239
  set: SetItem[];
@@ -269,6 +272,7 @@ export interface CreateTableStmt {
269
272
  constraints: TableConstraint[];
270
273
  asSelect: SelectStmt | null;
271
274
  withoutRowid: boolean;
275
+ strict: boolean;
272
276
  }
273
277
  export interface ColumnDef {
274
278
  name: string;
@@ -301,6 +305,8 @@ export type ColumnConstraint = {
301
305
  columns: string[] | null;
302
306
  onDelete: FkAction | null;
303
307
  onUpdate: FkAction | null;
308
+ deferrable: boolean;
309
+ initiallyDeferred: boolean;
304
310
  } | {
305
311
  type: "generated";
306
312
  expr: Expr;
@@ -327,11 +333,15 @@ export type TableConstraint = {
327
333
  onDelete: FkAction | null;
328
334
  onUpdate: FkAction | null;
329
335
  name: string | null;
336
+ deferrable: boolean;
337
+ initiallyDeferred: boolean;
330
338
  };
331
339
  export interface IndexedColumn {
332
340
  name: string;
333
341
  collate: string | null;
334
342
  order: "ASC" | "DESC" | null;
343
+ /** Present when the index key is an expression rather than a bare column. */
344
+ expr?: Expr | null;
335
345
  }
336
346
  export type ConflictAction = "ROLLBACK" | "ABORT" | "FAIL" | "IGNORE" | "REPLACE";
337
347
  export type FkAction = "SET NULL" | "SET DEFAULT" | "CASCADE" | "RESTRICT" | "NO ACTION";
@@ -448,4 +458,3 @@ export interface ExplainStmt {
448
458
  queryPlan: boolean;
449
459
  statement: Statement;
450
460
  }
451
- //# sourceMappingURL=nodes.d.ts.map
@@ -1,12 +1,11 @@
1
- import type { Expr } from "../ast/nodes.ts";
2
- import type { IndexStore } from "../indexes/index.ts";
3
- import type { Row, Rowid } from "../storage/row.ts";
4
- import type { ColumnInfo, Table } from "../storage/table.ts";
5
- import type { SqlValue } from "../types/value.ts";
1
+ import type { Expr } from "../ast/nodes.js";
2
+ import type { IndexStore } from "../indexes/index.js";
3
+ import type { Row, Rowid } from "../storage/row.js";
4
+ import type { ColumnInfo, Table } from "../storage/table.js";
5
+ import type { SqlValue } from "../types/value.js";
6
6
  export type CheckEvaluator = (expr: Expr, row: Row) => SqlValue;
7
7
  export declare function checkNotNull(columns: readonly ColumnInfo[], row: Row, tableName?: string): void;
8
8
  export declare function checkPrimaryKey(columns: readonly ColumnInfo[], row: Row, tableName?: string): void;
9
9
  export declare function checkUnique(index: IndexStore, values: readonly SqlValue[], rowid?: Rowid): void;
10
10
  export declare function checkExpressions(expressions: readonly Expr[], row: Row, evaluate: CheckEvaluator, constraintName?: string): void;
11
11
  export declare function checkTableConstraints(table: Table, row: Row, evaluate: CheckEvaluator): void;
12
- //# sourceMappingURL=check.d.ts.map
@@ -1,7 +1,41 @@
1
- export type ErrorCategory = "syntax" | "no_such_table" | "no_such_column" | "constraint_unique" | "constraint_primary" | "constraint_notnull" | "constraint_check" | "constraint_foreign" | "constraint" | "transaction" | "datatype_mismatch" | "unsupported" | "misuse" | "other";
1
+ /** Coarse classification of {@link SqliteError} for catch-site branching.
2
+ *
3
+ * New categories may be added in minor releases. Consumers that switch on
4
+ * `category` must include a default case.
5
+ */
6
+ export type ErrorCategory = "syntax" | "no_such_table" | "no_such_column" | "constraint_unique" | "constraint_primary" | "constraint_notnull" | "constraint_check" | "constraint_foreign" | "constraint" | "transaction" | "datatype_mismatch" | "unsupported" | "misuse" | "snapshot_version" | "other" | (string & {});
7
+ /**
8
+ * Engine error. `name` is always `"SqliteError"`.
9
+ *
10
+ * `sqliteCode` and Node's conventional `code` property are always set (default
11
+ * `"SQLITE_ERROR"` when no more specific code applies).
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { Database, SqliteError } from "@crvouga/sqlite-mem";
16
+ *
17
+ * const db = new Database();
18
+ * try {
19
+ * db.exec("SELECT * FROM missing");
20
+ * } catch (err) {
21
+ * if (err instanceof SqliteError && err.category === "no_such_table") {
22
+ * // handle
23
+ * }
24
+ * }
25
+ * ```
26
+ */
2
27
  export declare class SqliteError extends Error {
28
+ /** Coarse error class (constraint vs syntax vs missing object, …). */
3
29
  readonly category: ErrorCategory;
4
- readonly sqliteCode?: string;
30
+ /** SQLite result-code name such as `SQLITE_CONSTRAINT_UNIQUE`. */
31
+ readonly sqliteCode: string;
32
+ /** Same value as {@link sqliteCode} (Node `err.code` convention). */
33
+ readonly code: string;
34
+ /**
35
+ * @param message - Human-readable error text.
36
+ * @param category - Coarse class; defaults to `"other"`.
37
+ * @param sqliteCode - SQLite result-code name; defaults to `"SQLITE_ERROR"`.
38
+ */
5
39
  constructor(message: string, category?: ErrorCategory, sqliteCode?: string);
6
40
  }
7
41
  export declare function unsupported(feature: string): never;
@@ -9,4 +43,3 @@ export declare class TriggerRaiseError extends SqliteError {
9
43
  readonly action: "IGNORE" | "ABORT" | "FAIL" | "ROLLBACK";
10
44
  constructor(action: "IGNORE" | "ABORT" | "FAIL" | "ROLLBACK", message?: string);
11
45
  }
12
- //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,5 @@
1
- import type { AttachStmt, DetachStmt } from "../ast/nodes.ts";
2
- import type { ExecutionEnv } from "./env.ts";
3
- import { type ResultSet } from "./result.ts";
1
+ import type { AttachStmt, DetachStmt } from "../ast/nodes.js";
2
+ import type { ExecutionEnv } from "./env.js";
3
+ import { type ResultSet } from "./result.js";
4
4
  export declare function executeAttach(stmt: AttachStmt, env: ExecutionEnv): ResultSet;
5
5
  export declare function executeDetach(stmt: DetachStmt, env: ExecutionEnv): ResultSet;
6
- //# sourceMappingURL=attach.d.ts.map
@@ -1,6 +1,6 @@
1
- import type { AlterTableStmt, CreateIndexStmt, CreateTableStmt, CreateViewStmt, DropIndexStmt, DropTableStmt, DropViewStmt } from "../ast/nodes.ts";
2
- import type { ExecutionEnv } from "./env.ts";
3
- import { type ResultSet } from "./result.ts";
1
+ import type { AlterTableStmt, CreateIndexStmt, CreateTableStmt, CreateViewStmt, DropIndexStmt, DropTableStmt, DropViewStmt } from "../ast/nodes.js";
2
+ import type { ExecutionEnv } from "./env.js";
3
+ import { type ResultSet } from "./result.js";
4
4
  export declare function executeCreateTable(stmt: CreateTableStmt, env: ExecutionEnv): ResultSet;
5
5
  export declare function executeCreateIndex(stmt: CreateIndexStmt, env: ExecutionEnv): ResultSet;
6
6
  export declare function executeAlterTable(stmt: AlterTableStmt, env: ExecutionEnv): ResultSet;
@@ -8,4 +8,3 @@ export declare function executeDropTable(stmt: DropTableStmt, env: ExecutionEnv)
8
8
  export declare function executeDropIndex(stmt: DropIndexStmt, env: ExecutionEnv): ResultSet;
9
9
  export declare function executeCreateView(stmt: CreateViewStmt, env: ExecutionEnv): ResultSet;
10
10
  export declare function executeDropView(stmt: DropViewStmt, env: ExecutionEnv): ResultSet;
11
- //# sourceMappingURL=ddl.d.ts.map
@@ -1,7 +1,7 @@
1
- import type { DeleteStmt, InsertStmt, UpdateStmt } from "../ast/nodes.ts";
2
- import type { ExecutionEnv } from "./env.ts";
3
- import { type ResultSet } from "./result.ts";
1
+ import type { DeleteStmt, InsertStmt, UpdateStmt } from "../ast/nodes.js";
2
+ import type { ExecutionEnv } from "./env.js";
3
+ import { type ResultSet } from "./result.js";
4
4
  export declare function executeInsert(stmt: InsertStmt, env: ExecutionEnv): ResultSet;
5
5
  export declare function executeUpdate(stmt: UpdateStmt, env: ExecutionEnv): ResultSet;
6
6
  export declare function executeDelete(stmt: DeleteStmt, env: ExecutionEnv): ResultSet;
7
- //# sourceMappingURL=dml.d.ts.map
7
+ export declare function checkDeferredForeignKeys(env: ExecutionEnv): void;
@@ -1,12 +1,11 @@
1
- import type { SelectStmt } from "../ast/nodes.ts";
2
- import type { EvalContext } from "../expressions/context.ts";
3
- import { type FunctionRegistry } from "../functions/registry.ts";
4
- import type { DatabaseState } from "../storage/database-state.ts";
5
- import type { Rowid } from "../storage/row.ts";
6
- import type { TransactionManager } from "../transactions/manager.ts";
7
- import type { SqlValue } from "../types/value.ts";
8
- import { type Affinity } from "../types/value.ts";
9
- import type { ResultSet } from "./result.ts";
1
+ import type { SelectStmt } from "../ast/nodes.js";
2
+ import type { EvalContext } from "../expressions/context.js";
3
+ import { type FunctionRegistry } from "../functions/registry.js";
4
+ import type { DatabaseState } from "../storage/database-state.js";
5
+ import type { Rowid } from "../storage/row.js";
6
+ import type { TransactionManager } from "../transactions/manager.js";
7
+ import type { ResultSet } from "./result.js";
8
+ import { type Affinity, type SqlValue } from "../types/value.js";
10
9
  export interface Cell {
11
10
  table: string | null;
12
11
  tableLower?: string | null;
@@ -26,7 +25,7 @@ export interface ScopeRow {
26
25
  rowidName?: string;
27
26
  sourceTable?: string;
28
27
  /** Set when WHERE MATCH succeeds for this row. */
29
- ftsMatch?: import("../vtable/fts5.ts").FtsMatchCursor | null;
28
+ ftsMatch?: import("../vtable/fts5.js").FtsMatchCursor | null;
30
29
  }
31
30
  export type SelectRunner = (stmt: SelectStmt, env: ExecutionEnv, parent?: EvalContext) => ResultSet;
32
31
  export interface ExecutionHooks {
@@ -59,4 +58,3 @@ export declare class ExecutionEnv {
59
58
  createEvalContext(row?: ScopeRow | null, parent?: EvalContext): EvalContext;
60
59
  }
61
60
  export declare function toSqlValue(value: unknown): SqlValue;
62
- //# sourceMappingURL=env.d.ts.map
@@ -1,5 +1,4 @@
1
- import type { Statement } from "../ast/nodes.ts";
2
- import type { ExecutionEnv } from "./env.ts";
3
- import { type ResultSet } from "./result.ts";
1
+ import type { Statement } from "../ast/nodes.js";
2
+ import type { ExecutionEnv } from "./env.js";
3
+ import { type ResultSet } from "./result.js";
4
4
  export declare function executeStatement(stmt: Statement, env: ExecutionEnv): ResultSet;
5
- //# sourceMappingURL=execute.d.ts.map
@@ -1,5 +1,4 @@
1
- import type { Expr } from "../ast/nodes.ts";
2
- import type { ExecutionEnv } from "./env.ts";
3
- import { type ResultSet } from "./result.ts";
1
+ import type { Expr } from "../ast/nodes.js";
2
+ import type { ExecutionEnv } from "./env.js";
3
+ import { type ResultSet } from "./result.js";
4
4
  export declare function executePragma(name: string, expr: Expr | null, env: ExecutionEnv): ResultSet;
5
- //# sourceMappingURL=pragma.d.ts.map
@@ -1,18 +1,22 @@
1
- import { type SqlValue } from "../types/value.ts";
1
+ import { type QueryRow, type QueryValue, type SqlValue } from "../types/value.js";
2
+ /** Query result returned by {@link Statement.result}. */
2
3
  export interface ResultSet {
4
+ /** Result-column names, in SELECT order. Present even when `rows` is empty. */
3
5
  columns: string[];
4
- rows: Record<string, SqlValue>[];
5
- /** Positional rows preserve duplicate result-column names for internal use. */
6
- values?: SqlValue[][];
6
+ /** Named rows. Duplicate column names keep the last value. */
7
+ rows: QueryRow[];
8
+ /** Positional rows; always present (empty array when there are zero rows). */
9
+ values: QueryValue[][];
10
+ /** Rows changed by the most recent mutating statement in this execution. */
7
11
  changes: number;
12
+ /** Rowid of the most recent INSERT in this execution. */
8
13
  lastInsertRowid: number | bigint;
9
14
  }
10
15
  export declare function emptyResult(changes?: number, lastInsertRowid?: number | bigint): ResultSet;
11
16
  /** Export engine values to the public JS surface (SqlReal → number, SqlJsonText → string). */
12
- export declare function exportSqlValue(value: SqlValue): SqlValue;
17
+ export declare function exportSqlValue(value: SqlValue): QueryValue;
13
18
  export declare function valuesToResult(columns: string[], values: SqlValue[][], changes?: number, lastInsertRowid?: number | bigint, options?: {
14
19
  named?: boolean;
15
20
  keepValues?: boolean;
16
21
  }): ResultSet;
17
22
  export declare function resultValues(result: ResultSet): SqlValue[][];
18
- //# sourceMappingURL=result.d.ts.map
@@ -1,7 +1,6 @@
1
- import type { FromItem, SelectStmt } from "../ast/nodes.ts";
2
- import type { EvalContext } from "../expressions/context.ts";
3
- import type { ExecutionEnv, ScopeRow } from "./env.ts";
4
- import { type ResultSet } from "./result.ts";
1
+ import type { FromItem, SelectStmt } from "../ast/nodes.js";
2
+ import type { EvalContext } from "../expressions/context.js";
3
+ import type { ExecutionEnv, ScopeRow } from "./env.js";
4
+ import { type ResultSet } from "./result.js";
5
5
  export declare function executeSelect(stmt: SelectStmt, env: ExecutionEnv, parent?: EvalContext): ResultSet;
6
6
  export declare function scanFrom(item: FromItem, env: ExecutionEnv, parent?: EvalContext): ScopeRow[];
7
- //# sourceMappingURL=select.d.ts.map
@@ -1,10 +1,9 @@
1
- import type { SelectStmt } from "../ast/nodes.ts";
2
- import type { ExecutionEnv } from "./env.ts";
3
- import { type ResultSet } from "./result.ts";
1
+ import type { SelectStmt } from "../ast/nodes.js";
2
+ import type { ExecutionEnv } from "./env.js";
3
+ import { type ResultSet } from "./result.js";
4
4
  /**
5
5
  * Tight path for `SELECT cols FROM table WHERE col = ?` (no join/group/order).
6
6
  * Skips ScopeRow / evalExpr and honors maxRows during the scan.
7
7
  */
8
8
  export declare function tryExecuteSimpleSelect(stmt: SelectStmt, env: ExecutionEnv): ResultSet | null;
9
9
  export declare function tryExecuteSimpleJoin(stmt: SelectStmt, env: ExecutionEnv): ResultSet | null;
10
- //# sourceMappingURL=simple-select.d.ts.map
@@ -1,12 +1,11 @@
1
- import type { CreateTriggerStmt, DropTriggerStmt } from "../ast/nodes.ts";
2
- import type { Row } from "../storage/row.ts";
3
- import type { Table } from "../storage/table.ts";
4
- import { type SqlValue } from "../types/value.ts";
5
- import type { ExecutionEnv } from "./env.ts";
6
- import { type ResultSet } from "./result.ts";
1
+ import type { CreateTriggerStmt, DropTriggerStmt } from "../ast/nodes.js";
2
+ import type { Row } from "../storage/row.js";
3
+ import type { Table } from "../storage/table.js";
4
+ import { type SqlValue } from "../types/value.js";
5
+ import type { ExecutionEnv } from "./env.js";
6
+ import { type ResultSet } from "./result.js";
7
7
  export declare function executeCreateTrigger(stmt: CreateTriggerStmt, env: ExecutionEnv): ResultSet;
8
8
  export declare function executeDropTrigger(stmt: DropTriggerStmt, env: ExecutionEnv): ResultSet;
9
9
  export declare function fireInsertTriggers(timing: "BEFORE" | "AFTER" | "INSTEAD", table: Table, values: Map<string, SqlValue>, oldRow: Row | null, env: ExecutionEnv): "ok" | "ignore";
10
10
  export declare function fireUpdateTriggers(timing: "BEFORE" | "AFTER", table: Table, oldRow: Row, newValues: Map<string, SqlValue>, updatedColumns: Set<string>, env: ExecutionEnv): "ok" | "ignore";
11
11
  export declare function fireDeleteTriggers(timing: "BEFORE" | "AFTER", table: Table, oldRow: Row, env: ExecutionEnv): "ok" | "ignore";
12
- //# sourceMappingURL=triggers.d.ts.map
@@ -1,8 +1,8 @@
1
- import type { CreateVirtualTableStmt } from "../ast/nodes.ts";
2
- import type { SqlValue } from "../types/value.ts";
3
- import type { Fts5VirtualTable } from "../vtable/fts5.ts";
4
- import type { ExecutionEnv } from "./env.ts";
5
- import { type ResultSet } from "./result.ts";
1
+ import type { CreateVirtualTableStmt } from "../ast/nodes.js";
2
+ import type { SqlValue } from "../types/value.js";
3
+ import type { Fts5VirtualTable } from "../vtable/fts5.js";
4
+ import type { ExecutionEnv } from "./env.js";
5
+ import { type ResultSet } from "./result.js";
6
6
  export declare function executeCreateVirtualTable(stmt: CreateVirtualTableStmt, env: ExecutionEnv): ResultSet;
7
7
  export declare function executeFtsInsert(table: Fts5VirtualTable, columnNames: string[], sourceRows: SqlValue[][], env: ExecutionEnv): {
8
8
  changes: number;
@@ -10,4 +10,3 @@ export declare function executeFtsInsert(table: Fts5VirtualTable, columnNames: s
10
10
  };
11
11
  export declare function executeFtsUpdate(table: Fts5VirtualTable, updates: Map<string, SqlValue>, rowids: Iterable<number | bigint>): number;
12
12
  export declare function executeFtsDelete(table: Fts5VirtualTable, rowids: Iterable<number | bigint>): number;
13
- //# sourceMappingURL=vtable.d.ts.map
@@ -1,7 +1,8 @@
1
- import type { SelectStmt } from "../ast/nodes.ts";
2
- import type { FunctionContext, FunctionRegistry } from "../functions/registry.ts";
3
- import type { SqlValue, StorageClass } from "../types/value.ts";
4
- import type { FtsMatchCursor } from "../vtable/fts5.ts";
1
+ import type { SelectStmt } from "../ast/nodes.js";
2
+ import type { FunctionContext, FunctionRegistry } from "../functions/registry.js";
3
+ import type { SqlValue, StorageClass } from "../types/value.js";
4
+ import type { FtsMatchCursor } from "../vtable/fts5.js";
5
+ /** Column / parameter / function resolution used by {@link evalExpr}. */
5
6
  export interface EvalContext {
6
7
  resolveColumn(table: string | null, name: string): SqlValue;
7
8
  resolveStorageClass?(table: string | null, name: string): StorageClass;
@@ -25,4 +26,3 @@ export interface EvalContext {
25
26
  functions?: FunctionRegistry;
26
27
  functionContext?: FunctionContext;
27
28
  }
28
- //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1,3 @@
1
+ import type { Expr } from "../ast/nodes.js";
2
+ /** Structural equality for matching WHERE expressions to index expressions. */
3
+ export declare function exprEquals(left: Expr, right: Expr): boolean;
@@ -1,5 +1,10 @@
1
- import type { Expr } from "../ast/nodes.ts";
2
- import { type SqlValue } from "../types/value.ts";
3
- import type { EvalContext } from "./context.ts";
1
+ import type { Expr } from "../ast/nodes.js";
2
+ import { type SqlValue } from "../types/value.js";
3
+ import type { EvalContext } from "./context.js";
4
+ /**
5
+ * Evaluate a parsed SQL expression against `ctx` (columns, parameters, functions).
6
+ *
7
+ * @param expr - Expression AST node from {@link parse}.
8
+ * @param ctx - Column / parameter / function resolution.
9
+ */
4
10
  export declare function evalExpr(expr: Expr, ctx: EvalContext): SqlValue;
5
- //# sourceMappingURL=eval.d.ts.map
@@ -1,4 +1,3 @@
1
- export type { EvalContext } from "./context.ts";
2
- export { evalExpr } from "./eval.ts";
3
- export { globMatch, likeMatch } from "./like.ts";
4
- //# sourceMappingURL=index.d.ts.map
1
+ export type { EvalContext } from "./context.js";
2
+ export { evalExpr } from "./eval.js";
3
+ export { globMatch, likeMatch } from "./like.js";
@@ -1,5 +1,15 @@
1
- /** SQLite LIKE matching. ASCII letters are case-insensitive. */
1
+ /**
2
+ * SQLite LIKE matching. ASCII letters are case-insensitive.
3
+ *
4
+ * @param text - Value to test.
5
+ * @param pattern - Pattern with `%` / `_` wildcards.
6
+ * @param escape - Optional single-character ESCAPE (or `null`).
7
+ */
2
8
  export declare function likeMatch(text: string, pattern: string, escape?: string | null): boolean;
3
- /** SQLite GLOB matching. GLOB is case-sensitive and uses Unix wildcards. */
9
+ /**
10
+ * SQLite GLOB matching. GLOB is case-sensitive and uses Unix `*` / `?` wildcards.
11
+ *
12
+ * @param text - Value to test.
13
+ * @param pattern - GLOB pattern.
14
+ */
4
15
  export declare function globMatch(text: string, pattern: string): boolean;
5
- //# sourceMappingURL=like.d.ts.map
@@ -1,4 +1,4 @@
1
- import { type SqlValue } from "../types/value.ts";
1
+ import { type SqlValue } from "../types/value.js";
2
2
  export interface AggregateAccumulator {
3
3
  step(args: SqlValue[]): void;
4
4
  finalize(): SqlValue;
@@ -6,4 +6,3 @@ export interface AggregateAccumulator {
6
6
  export type AggregateFactory = () => AggregateAccumulator;
7
7
  export declare const aggregateFunctions: Readonly<Record<string, AggregateFactory>>;
8
8
  export declare function createAggregate(name: string): AggregateAccumulator | undefined;
9
- //# sourceMappingURL=aggregate.d.ts.map
@@ -1,3 +1,2 @@
1
- import type { ScalarFunction } from "./registry.ts";
1
+ import type { ScalarFunction } from "./registry.js";
2
2
  export declare const dateTimeFunctions: Readonly<Record<string, ScalarFunction>>;
3
- //# sourceMappingURL=datetime.d.ts.map