@crvouga/mockingbird-service-sqlite 0.1.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 (100) hide show
  1. package/AGENTS.md +170 -0
  2. package/COMPATIBILITY-AUDIT.md +236 -0
  3. package/COMPATIBILITY.md +102 -0
  4. package/LICENSE +21 -0
  5. package/README.md +405 -0
  6. package/compat/coverage.json +22231 -0
  7. package/compat/divergences.json +145 -0
  8. package/compat/fts-oracle-surface.json +198 -0
  9. package/compat/requirements.json +20929 -0
  10. package/compat/scenario-types.ts +63 -0
  11. package/compat/scenarios.ts +871 -0
  12. package/compat/smoke-baseline.json +3 -0
  13. package/compat/sqllogictest-skip.json +5 -0
  14. package/dist/api/database.d.ts +112 -0
  15. package/dist/api/snapshot.d.ts +21 -0
  16. package/dist/api/statement.d.ts +75 -0
  17. package/dist/ast/nodes.d.ts +476 -0
  18. package/dist/constraints/check.d.ts +11 -0
  19. package/dist/errors/index.d.ts +45 -0
  20. package/dist/executor/attach.d.ts +5 -0
  21. package/dist/executor/ddl.d.ts +10 -0
  22. package/dist/executor/dml.d.ts +7 -0
  23. package/dist/executor/env.d.ts +66 -0
  24. package/dist/executor/execute.d.ts +4 -0
  25. package/dist/executor/pragma-engine.d.ts +31 -0
  26. package/dist/executor/pragma.d.ts +4 -0
  27. package/dist/executor/result.d.ts +22 -0
  28. package/dist/executor/select.d.ts +7 -0
  29. package/dist/executor/simple-select.d.ts +9 -0
  30. package/dist/executor/triggers.d.ts +11 -0
  31. package/dist/executor/vtable.d.ts +12 -0
  32. package/dist/expressions/context.d.ts +30 -0
  33. package/dist/expressions/equals.d.ts +3 -0
  34. package/dist/expressions/eval.d.ts +12 -0
  35. package/dist/expressions/index.d.ts +3 -0
  36. package/dist/expressions/like.d.ts +16 -0
  37. package/dist/functions/aggregate.d.ts +8 -0
  38. package/dist/functions/datetime.d.ts +2 -0
  39. package/dist/functions/extensions.d.ts +7 -0
  40. package/dist/functions/index.d.ts +8 -0
  41. package/dist/functions/json.d.ts +6 -0
  42. package/dist/functions/math.d.ts +2 -0
  43. package/dist/functions/pragma-tvf.d.ts +8 -0
  44. package/dist/functions/registry.d.ts +39 -0
  45. package/dist/functions/scalar.d.ts +9 -0
  46. package/dist/functions/table-valued-registry.d.ts +11 -0
  47. package/dist/functions/table-valued.d.ts +13 -0
  48. package/dist/functions/window.d.ts +23 -0
  49. package/dist/index.d.ts +28 -0
  50. package/dist/index.js +16010 -0
  51. package/dist/index.js.map +7 -0
  52. package/dist/indexes/index.d.ts +48 -0
  53. package/dist/indexes/keys.d.ts +15 -0
  54. package/dist/json/index.d.ts +7 -0
  55. package/dist/json/jsonb.d.ts +42 -0
  56. package/dist/json/ops.d.ts +24 -0
  57. package/dist/json/parse.d.ts +13 -0
  58. package/dist/json/path.d.ts +26 -0
  59. package/dist/json/stringify.d.ts +4 -0
  60. package/dist/json/tvf.d.ts +13 -0
  61. package/dist/json/types.d.ts +29 -0
  62. package/dist/lexer/tokenize.d.ts +23 -0
  63. package/dist/parser/index.d.ts +17 -0
  64. package/dist/parser/parser.d.ts +115 -0
  65. package/dist/planner/access.d.ts +50 -0
  66. package/dist/planner/index.d.ts +3 -0
  67. package/dist/runtime/assert.d.ts +11 -0
  68. package/dist/runtime/catch.d.ts +3 -0
  69. package/dist/runtime/clock.d.ts +14 -0
  70. package/dist/runtime/index.d.ts +3 -0
  71. package/dist/runtime/options.d.ts +25 -0
  72. package/dist/runtime/prng.d.ts +42 -0
  73. package/dist/schema/catalog.d.ts +14 -0
  74. package/dist/schema/master-sql.d.ts +10 -0
  75. package/dist/serialization/codec.d.ts +19 -0
  76. package/dist/serialization/index.d.ts +1 -0
  77. package/dist/serialization/wire.d.ts +61 -0
  78. package/dist/storage/columnar-slab.d.ts +58 -0
  79. package/dist/storage/database-state.d.ts +96 -0
  80. package/dist/storage/index.d.ts +6 -0
  81. package/dist/storage/row.d.ts +13 -0
  82. package/dist/storage/table.d.ts +119 -0
  83. package/dist/transactions/manager.d.ts +19 -0
  84. package/dist/types/collation.d.ts +4 -0
  85. package/dist/types/sqlite-atof.d.ts +4 -0
  86. package/dist/types/sqlite-real-format.d.ts +5 -0
  87. package/dist/types/strict.d.ts +6 -0
  88. package/dist/types/value.d.ts +88 -0
  89. package/dist/unstable.d.ts +20 -0
  90. package/dist/unstable.js +10343 -0
  91. package/dist/unstable.js.map +7 -0
  92. package/dist/vtable/fts/options.d.ts +34 -0
  93. package/dist/vtable/fts/porter.d.ts +2 -0
  94. package/dist/vtable/fts/query.d.ts +39 -0
  95. package/dist/vtable/fts/table.d.ts +78 -0
  96. package/dist/vtable/fts/tokenize.d.ts +20 -0
  97. package/dist/vtable/fts5.d.ts +1 -0
  98. package/dist/vtable/index.d.ts +2 -0
  99. package/dist/vtable/modules.d.ts +65 -0
  100. package/package.json +122 -0
@@ -0,0 +1,3 @@
1
+ {
2
+ "ids": []
3
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "files": [],
3
+ "prefixes": [],
4
+ "notes": "Add vendor/sqllogictest/test/<file> or <file>#<line> entries when a record is intentionally unsupported."
5
+ }
@@ -0,0 +1,112 @@
1
+ import { type DatabaseOptions, type RandomMode } from "../runtime/index.js";
2
+ import type { BindValue, QueryRow } from "../types/value.js";
3
+ import { type Snapshot } from "./snapshot.js";
4
+ import { Statement } from "./statement.js";
5
+ /**
6
+ * Pure TypeScript in-memory SQLite database.
7
+ *
8
+ * Deterministic by default: `random()` / `randomblob()` use a seeded PRNG
9
+ * (`seed` defaults to `1`) and `date('now')` / friends use a fixed clock
10
+ * (`2000-01-01T00:00:00.000Z`). Pass `{ random: "os" }` and `{ now: "system" }`
11
+ * for SQLite-like CSPRNG and wall-clock `'now'`. There is no filesystem or WASM.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { Database } from "@crvouga/mockingbird-service-sqlite";
16
+ *
17
+ * const db = new Database();
18
+ * db.exec("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT NOT NULL)");
19
+ * db.prepare("INSERT INTO users (name) VALUES (?)").run("Alice");
20
+ * const users = db.query<{ id: number; name: string }>("SELECT * FROM users");
21
+ * ```
22
+ */
23
+ export declare class Database {
24
+ /** Seed used to construct the PRNG. Ignored when {@link randomMode} is `"os"`. */
25
+ readonly seed: number | bigint;
26
+ /** Entropy mode for `random()` / `randomblob()`. */
27
+ readonly randomMode: RandomMode;
28
+ private closed;
29
+ private transactionSequence;
30
+ /** Depth of active {@link transaction} callbacks (not SQL BEGIN). */
31
+ private apiTransactionDepth;
32
+ /**
33
+ * Create an empty in-memory database.
34
+ *
35
+ * @param options - Determinism knobs. See {@link DatabaseOptions}.
36
+ */
37
+ constructor(options?: DatabaseOptions);
38
+ /**
39
+ * Execute SQL for its side effects (DDL/DML). Multiple statements are allowed.
40
+ *
41
+ * Does not accept bind parameters — use {@link prepare} or {@link query}.
42
+ *
43
+ * @param sql - SQL to run (semicolon-separated statements are ok).
44
+ * @throws {SqliteError} If the database is closed, extra arguments are passed, or the SQL fails.
45
+ */
46
+ exec(sql: string): void;
47
+ /**
48
+ * Execute a single-statement query and return all rows as objects keyed by column name.
49
+ *
50
+ * @typeParam T - Row shape. Defaults to {@link QueryRow}.
51
+ * @param sql - A single SQL statement (trailing `;` is fine).
52
+ * @param params - Bound parameters for `?` / `:name` placeholders.
53
+ * @returns All result rows.
54
+ * @throws {SqliteError} If the database is closed, `sql` is not a single statement, or execution fails.
55
+ */
56
+ query<T = QueryRow>(sql: string, params?: readonly BindValue[]): T[];
57
+ /**
58
+ * Compile a single SQL statement into a reusable {@link Statement}.
59
+ *
60
+ * @param sql - A single SQL statement (trailing `;` is fine). Multi-statement scripts are rejected.
61
+ * @throws {SqliteError} If the database is closed or `sql` cannot be prepared as one statement.
62
+ */
63
+ prepare(sql: string): Statement;
64
+ /**
65
+ * Run `fn` inside a transaction. Commits on success; rolls back if `fn` throws.
66
+ *
67
+ * Nested calls use SAVEPOINTs so an inner failure does not abort the outer
68
+ * transaction. Calling {@link close} from inside `fn` throws `misuse`.
69
+ *
70
+ * @param fn - Work to run while the transaction is open.
71
+ * @returns The value returned by `fn`.
72
+ * @throws {SqliteError} If the database is closed. Re-throws whatever `fn` throws after rollback.
73
+ */
74
+ transaction<T>(fn: () => T): T;
75
+ /**
76
+ * Freeze this database into a reusable {@link Snapshot} template.
77
+ *
78
+ * Does not encode SQLM bytes. Call {@link Snapshot.encode} to persist, or
79
+ * {@link Snapshot.open} for a copy-on-write fork.
80
+ *
81
+ * @throws {SqliteError} If the database is closed or a transaction is open.
82
+ */
83
+ snapshot(): Snapshot;
84
+ /**
85
+ * Close the database. Further SQL throws {@link SqliteError}. Idempotent.
86
+ *
87
+ * Rolls back an open SQL transaction, if any. Throws if called from inside
88
+ * a {@link transaction} callback.
89
+ */
90
+ close(): void;
91
+ /**
92
+ * Rows changed by the most recent INSERT / UPDATE / DELETE (SQLite `changes()`).
93
+ *
94
+ * @throws {SqliteError} If the database is closed.
95
+ */
96
+ get changes(): number;
97
+ /**
98
+ * Rowid of the most recent INSERT (SQLite `last_insert_rowid()`).
99
+ *
100
+ * @throws {SqliteError} If the database is closed.
101
+ */
102
+ get lastInsertRowid(): number | bigint;
103
+ /**
104
+ * Cumulative rows changed by INSERT / UPDATE / DELETE (SQLite `total_changes()`).
105
+ *
106
+ * @throws {SqliteError} If the database is closed.
107
+ */
108
+ get totalChanges(): number;
109
+ private prepareSingle;
110
+ }
111
+ export { Snapshot } from "./snapshot.js";
112
+ export type { DatabaseOptions };
@@ -0,0 +1,21 @@
1
+ import { type DatabaseOptions } from "../runtime/index.js";
2
+ import { type Database } from "./database.js";
3
+ /**
4
+ * Frozen in-memory database template. {@link open} is a copy-on-write fork.
5
+ * Encoded SQLM bytes are produced lazily via {@link encode}.
6
+ */
7
+ export declare class Snapshot {
8
+ private cachedBytes;
9
+ /** Encoded SQLM blob. Computed once; never mutates a buffer passed to {@link decode}. */
10
+ encode(): Uint8Array;
11
+ /**
12
+ * Copy-on-write database from this frozen template. Does not re-encode or re-decode.
13
+ */
14
+ open(options?: DatabaseOptions): Database;
15
+ /**
16
+ * Decode `bytes` once and freeze the result. The same `Uint8Array` object
17
+ * returns the same {@link Snapshot} (WeakMap), so later {@link open} calls
18
+ * are copy-on-write forks after the first hydrate.
19
+ */
20
+ static decode(bytes: Uint8Array): Snapshot;
21
+ }
@@ -0,0 +1,75 @@
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/mockingbird-service-sqlite";
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
+ */
28
+ export declare class Statement {
29
+ private readonly database;
30
+ private readonly sql;
31
+ private namedPlan;
32
+ private env;
33
+ private statements;
34
+ private statementSqls;
35
+ private schemaVersion;
36
+ private constructor();
37
+ /**
38
+ * Execute for side effects (INSERT / UPDATE / DELETE / DDL).
39
+ *
40
+ * @param params - Bind values for this call only.
41
+ * @returns Mutation counters for this execution.
42
+ * @throws {SqliteError} If the database is closed, the statement is empty, or execution fails.
43
+ */
44
+ run(...params: BindValue[]): RunResult;
45
+ /**
46
+ * Execute and return every result row as an object keyed by column name.
47
+ *
48
+ * @typeParam T - Row shape. Defaults to {@link QueryRow}.
49
+ * @param params - Bind values for this call only.
50
+ * @throws {SqliteError} If the database is closed, the statement is empty, or execution fails.
51
+ */
52
+ all<T = QueryRow>(...params: BindValue[]): T[];
53
+ /**
54
+ * Execute and return the full {@link ResultSet}, including column names.
55
+ *
56
+ * Use this when you need metadata for an empty result (column names with zero rows).
57
+ * {@link all} only returns row objects.
58
+ *
59
+ * @param params - Bind values for this call only.
60
+ * @throws {SqliteError} If the database is closed, the statement is empty, or execution fails.
61
+ */
62
+ result(...params: BindValue[]): ResultSet;
63
+ /**
64
+ * Execute and return the first row, or `undefined` if there are no rows.
65
+ *
66
+ * @typeParam T - Row shape. Defaults to {@link QueryRow}.
67
+ * @param params - Bind values for this call only.
68
+ * @throws {SqliteError} If the database is closed, the statement is empty, or execution fails.
69
+ */
70
+ get<T = QueryRow>(...params: BindValue[]): T | undefined;
71
+ private execute;
72
+ private obtainEnv;
73
+ private reprepareIfSchemaChanged;
74
+ private bindNamed;
75
+ }
@@ -0,0 +1,476 @@
1
+ import type { SqlValue } from "../types/value.js";
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
+ export type UnaryOp = "+" | "-" | "~" | "NOT";
4
+ /** Parsed SQL expression AST (literals, operators, functions, subqueries, …). */
5
+ export type Expr = LiteralExpr | NullExpr | ColumnRefExpr | UnaryExpr | BinaryExpr | BetweenExpr | InExpr | LikeExpr | IsBoolExpr | FunctionExpr | AggregateExpr | WindowExpr | CaseExpr | CastExpr | ExistsExpr | SubqueryExpr | ParameterExpr | RowExpr | CollateExpr;
6
+ export interface LiteralExpr {
7
+ type: "literal";
8
+ value: SqlValue;
9
+ /** True when the literal was written with float syntax (e.g. 1.0) or must be REAL. */
10
+ forceReal?: boolean;
11
+ }
12
+ export interface NullExpr {
13
+ type: "null";
14
+ }
15
+ export interface ColumnRefExpr {
16
+ type: "column";
17
+ table: string | null;
18
+ name: string;
19
+ }
20
+ export interface UnaryExpr {
21
+ type: "unary";
22
+ op: UnaryOp;
23
+ expr: Expr;
24
+ }
25
+ export interface BinaryExpr {
26
+ type: "binary";
27
+ op: BinaryOp;
28
+ left: Expr;
29
+ right: Expr;
30
+ }
31
+ /** `expr IS [NOT] TRUE` / `expr IS [NOT] FALSE` (truthiness, not equality to 1/0). */
32
+ export interface IsBoolExpr {
33
+ type: "is_bool";
34
+ expr: Expr;
35
+ not: boolean;
36
+ /** `true` for TRUE, `false` for FALSE. */
37
+ sense: boolean;
38
+ }
39
+ export interface BetweenExpr {
40
+ type: "between";
41
+ not: boolean;
42
+ expr: Expr;
43
+ lower: Expr;
44
+ upper: Expr;
45
+ }
46
+ export interface InExpr {
47
+ type: "in";
48
+ not: boolean;
49
+ expr: Expr;
50
+ values: Expr[] | SelectStmt;
51
+ }
52
+ export interface LikeExpr {
53
+ type: "like";
54
+ not: boolean;
55
+ op: "LIKE" | "GLOB";
56
+ expr: Expr;
57
+ pattern: Expr;
58
+ escape: Expr | null;
59
+ }
60
+ export interface FunctionExpr {
61
+ type: "function";
62
+ name: string;
63
+ distinct: boolean;
64
+ args: Expr[] | "*";
65
+ orderBy: OrderByItem[];
66
+ filter: Expr | null;
67
+ }
68
+ export interface AggregateExpr {
69
+ type: "aggregate";
70
+ name: string;
71
+ distinct: boolean;
72
+ args: Expr[] | "*";
73
+ orderBy: OrderByItem[];
74
+ filter: Expr | null;
75
+ }
76
+ export interface WindowExpr {
77
+ type: "window";
78
+ func: FunctionExpr | AggregateExpr;
79
+ window: WindowSpec;
80
+ }
81
+ export interface WindowSpec {
82
+ partitionBy: Expr[];
83
+ orderBy: OrderByItem[];
84
+ frame: FrameSpec | null;
85
+ /** Named window reference for `OVER window_name`. */
86
+ ref?: string | null;
87
+ }
88
+ export interface FrameSpec {
89
+ type: "ROWS" | "RANGE" | "GROUPS";
90
+ start: FrameBound;
91
+ end: FrameBound;
92
+ exclude: "no_others" | "current_row" | "group" | "ties" | null;
93
+ }
94
+ export type FrameBound = {
95
+ kind: "unbounded_preceding";
96
+ } | {
97
+ kind: "unbounded_following";
98
+ } | {
99
+ kind: "current_row";
100
+ } | {
101
+ kind: "preceding";
102
+ expr: Expr;
103
+ } | {
104
+ kind: "following";
105
+ expr: Expr;
106
+ };
107
+ export interface CaseExpr {
108
+ type: "case";
109
+ base: Expr | null;
110
+ whens: {
111
+ when: Expr;
112
+ then: Expr;
113
+ }[];
114
+ else: Expr | null;
115
+ }
116
+ export interface CastExpr {
117
+ type: "cast";
118
+ expr: Expr;
119
+ typeName: string;
120
+ }
121
+ export interface ExistsExpr {
122
+ type: "exists";
123
+ not: boolean;
124
+ select: SelectStmt;
125
+ }
126
+ export interface SubqueryExpr {
127
+ type: "subquery";
128
+ select: SelectStmt;
129
+ }
130
+ export interface ParameterExpr {
131
+ type: "parameter";
132
+ /** 1-based positional index, or named key */
133
+ name: string | number;
134
+ }
135
+ export interface RowExpr {
136
+ type: "row";
137
+ values: Expr[];
138
+ }
139
+ export interface CollateExpr {
140
+ type: "collate";
141
+ expr: Expr;
142
+ collation: string;
143
+ }
144
+ export interface OrderByItem {
145
+ expr: Expr;
146
+ dir: "ASC" | "DESC";
147
+ nulls: "FIRST" | "LAST" | null;
148
+ }
149
+ export interface LimitClause {
150
+ limit: Expr;
151
+ offset: Expr | null;
152
+ }
153
+ export type Statement = SelectStmt | InsertStmt | UpdateStmt | DeleteStmt | CreateTableStmt | DropTableStmt | AlterTableStmt | CreateIndexStmt | DropIndexStmt | CreateViewStmt | DropViewStmt | CreateTriggerStmt | DropTriggerStmt | BeginStmt | CommitStmt | RollbackStmt | SavepointStmt | ReleaseStmt | PragmaStmt | AttachStmt | DetachStmt | CreateVirtualTableStmt | ExplainStmt | AnalyzeStmt | ReindexStmt | VacuumStmt;
154
+ export interface AnalyzeStmt {
155
+ type: "analyze";
156
+ schema: string | null;
157
+ name: string | null;
158
+ }
159
+ export interface ReindexStmt {
160
+ type: "reindex";
161
+ schema: string | null;
162
+ name: string | null;
163
+ }
164
+ export interface VacuumStmt {
165
+ type: "vacuum";
166
+ schema: string | null;
167
+ into: string | null;
168
+ }
169
+ export interface SelectStmt {
170
+ type: "select";
171
+ with: WithClause | null;
172
+ distinct: boolean;
173
+ columns: ResultColumn[];
174
+ from: FromItem | null;
175
+ where: Expr | null;
176
+ groupBy: Expr[];
177
+ having: Expr | null;
178
+ windows: {
179
+ name: string;
180
+ spec: WindowSpec;
181
+ }[];
182
+ orderBy: OrderByItem[];
183
+ limit: LimitClause | null;
184
+ compound: CompoundTail | null;
185
+ }
186
+ export interface CompoundTail {
187
+ op: "UNION" | "UNION ALL" | "INTERSECT" | "EXCEPT";
188
+ select: SelectStmt;
189
+ }
190
+ export interface WithClause {
191
+ recursive: boolean;
192
+ ctes: Cte[];
193
+ }
194
+ export interface Cte {
195
+ name: string;
196
+ columns: string[] | null;
197
+ materialized: "materialized" | "not_materialized" | null;
198
+ select: SelectStmt;
199
+ }
200
+ export type ResultColumn = {
201
+ type: "star";
202
+ table: string | null;
203
+ } | {
204
+ type: "expr";
205
+ expr: Expr;
206
+ alias: string | null;
207
+ };
208
+ export type FromItem = TableRef | JoinFrom | SubqueryFrom | TableFuncFrom;
209
+ export interface TableRef {
210
+ type: "table";
211
+ schema: string | null;
212
+ name: string;
213
+ alias: string | null;
214
+ }
215
+ export interface SubqueryFrom {
216
+ type: "subquery";
217
+ select: SelectStmt;
218
+ alias: string;
219
+ }
220
+ export interface TableFuncFrom {
221
+ type: "table_func";
222
+ name: string;
223
+ args: Expr[];
224
+ alias: string | null;
225
+ }
226
+ export interface JoinFrom {
227
+ type: "join";
228
+ left: FromItem;
229
+ right: FromItem;
230
+ joinType: "CROSS" | "INNER" | "LEFT" | "RIGHT" | "FULL";
231
+ on: Expr | null;
232
+ using: string[] | null;
233
+ }
234
+ export interface InsertStmt {
235
+ type: "insert";
236
+ with: WithClause | null;
237
+ mode: "insert" | "replace" | "insert_or_replace" | "insert_or_ignore" | "insert_or_abort" | "insert_or_rollback" | "insert_or_fail";
238
+ table: string;
239
+ columns: string[] | null;
240
+ values: Expr[][] | null;
241
+ select: SelectStmt | null;
242
+ upsert: UpsertClause | null;
243
+ returning: ResultColumn[];
244
+ }
245
+ export interface UpsertClause {
246
+ targetColumns: string[] | null;
247
+ targetExprs: Expr[] | null;
248
+ targetWhere: Expr | null;
249
+ action: "nothing" | {
250
+ set: SetItem[];
251
+ where: Expr | null;
252
+ };
253
+ }
254
+ export interface SetItem {
255
+ columns: string[];
256
+ expr: Expr;
257
+ }
258
+ export interface UpdateStmt {
259
+ type: "update";
260
+ with: WithClause | null;
261
+ or: "replace" | "ignore" | "abort" | "rollback" | "fail" | null;
262
+ table: string;
263
+ alias: string | null;
264
+ set: SetItem[];
265
+ from: FromItem | null;
266
+ where: Expr | null;
267
+ returning: ResultColumn[];
268
+ }
269
+ export interface DeleteStmt {
270
+ type: "delete";
271
+ with: WithClause | null;
272
+ or: "replace" | "ignore" | "abort" | "rollback" | "fail" | null;
273
+ table: string;
274
+ alias: string | null;
275
+ where: Expr | null;
276
+ returning: ResultColumn[];
277
+ }
278
+ export interface CreateTableStmt {
279
+ type: "create_table";
280
+ ifNotExists: boolean;
281
+ temp: boolean;
282
+ name: string;
283
+ columns: ColumnDef[];
284
+ constraints: TableConstraint[];
285
+ asSelect: SelectStmt | null;
286
+ withoutRowid: boolean;
287
+ strict: boolean;
288
+ }
289
+ export interface ColumnDef {
290
+ name: string;
291
+ typeName: string | null;
292
+ constraints: ColumnConstraint[];
293
+ }
294
+ export type ColumnConstraint = {
295
+ type: "primary_key";
296
+ order: "ASC" | "DESC" | null;
297
+ autoincrement: boolean;
298
+ conflict: ConflictAction | null;
299
+ } | {
300
+ type: "not_null";
301
+ conflict: ConflictAction | null;
302
+ } | {
303
+ type: "unique";
304
+ conflict: ConflictAction | null;
305
+ } | {
306
+ type: "check";
307
+ expr: Expr;
308
+ } | {
309
+ type: "default";
310
+ expr: Expr;
311
+ } | {
312
+ type: "collate";
313
+ name: string;
314
+ } | {
315
+ type: "references";
316
+ table: string;
317
+ columns: string[] | null;
318
+ onDelete: FkAction | null;
319
+ onUpdate: FkAction | null;
320
+ match: FkMatch;
321
+ deferrable: boolean;
322
+ initiallyDeferred: boolean;
323
+ } | {
324
+ type: "generated";
325
+ expr: Expr;
326
+ stored: boolean;
327
+ };
328
+ export type TableConstraint = {
329
+ type: "primary_key";
330
+ columns: IndexedColumn[];
331
+ conflict: ConflictAction | null;
332
+ } | {
333
+ type: "unique";
334
+ columns: IndexedColumn[];
335
+ conflict: ConflictAction | null;
336
+ name: string | null;
337
+ } | {
338
+ type: "check";
339
+ expr: Expr;
340
+ name: string | null;
341
+ } | {
342
+ type: "foreign_key";
343
+ columns: string[];
344
+ refTable: string;
345
+ refColumns: string[] | null;
346
+ onDelete: FkAction | null;
347
+ onUpdate: FkAction | null;
348
+ match: FkMatch;
349
+ name: string | null;
350
+ deferrable: boolean;
351
+ initiallyDeferred: boolean;
352
+ };
353
+ export interface IndexedColumn {
354
+ name: string;
355
+ collate: string | null;
356
+ order: "ASC" | "DESC" | null;
357
+ /** Present when the index key is an expression rather than a bare column. */
358
+ expr?: Expr | null;
359
+ }
360
+ export type ConflictAction = "ROLLBACK" | "ABORT" | "FAIL" | "IGNORE" | "REPLACE";
361
+ export type FkAction = "SET NULL" | "SET DEFAULT" | "CASCADE" | "RESTRICT" | "NO ACTION";
362
+ /** SQLite MATCH clause; FULL rejects partial-NULL composite keys. PARTIAL is accepted as SIMPLE. */
363
+ export type FkMatch = "SIMPLE" | "FULL" | "PARTIAL";
364
+ export interface DropTableStmt {
365
+ type: "drop_table";
366
+ ifExists: boolean;
367
+ name: string;
368
+ }
369
+ export interface AlterTableStmt {
370
+ type: "alter_table";
371
+ table: string;
372
+ action: {
373
+ kind: "rename_table";
374
+ newName: string;
375
+ } | {
376
+ kind: "rename_column";
377
+ oldName: string;
378
+ newName: string;
379
+ } | {
380
+ kind: "add_column";
381
+ column: ColumnDef;
382
+ } | {
383
+ kind: "drop_column";
384
+ name: string;
385
+ };
386
+ }
387
+ export interface CreateIndexStmt {
388
+ type: "create_index";
389
+ unique: boolean;
390
+ ifNotExists: boolean;
391
+ name: string;
392
+ table: string;
393
+ columns: IndexedColumn[];
394
+ where: Expr | null;
395
+ }
396
+ export interface DropIndexStmt {
397
+ type: "drop_index";
398
+ ifExists: boolean;
399
+ name: string;
400
+ }
401
+ export interface CreateViewStmt {
402
+ type: "create_view";
403
+ ifNotExists: boolean;
404
+ temp: boolean;
405
+ name: string;
406
+ columns: string[] | null;
407
+ select: SelectStmt;
408
+ }
409
+ export interface DropViewStmt {
410
+ type: "drop_view";
411
+ ifExists: boolean;
412
+ name: string;
413
+ }
414
+ export interface CreateTriggerStmt {
415
+ type: "create_trigger";
416
+ ifNotExists: boolean;
417
+ temp: boolean;
418
+ name: string;
419
+ timing: "BEFORE" | "AFTER" | "INSTEAD";
420
+ event: "INSERT" | "UPDATE" | "DELETE";
421
+ table: string;
422
+ updateColumns: string[] | null;
423
+ forEachRow: boolean;
424
+ when: Expr | null;
425
+ body: Statement[];
426
+ }
427
+ export interface DropTriggerStmt {
428
+ type: "drop_trigger";
429
+ ifExists: boolean;
430
+ name: string;
431
+ }
432
+ export interface CreateVirtualTableStmt {
433
+ type: "create_virtual_table";
434
+ ifNotExists: boolean;
435
+ name: string;
436
+ module: string;
437
+ moduleArgs: string[];
438
+ }
439
+ export interface BeginStmt {
440
+ type: "begin";
441
+ mode: "DEFERRED" | "IMMEDIATE" | "EXCLUSIVE" | null;
442
+ }
443
+ export interface CommitStmt {
444
+ type: "commit";
445
+ }
446
+ export interface RollbackStmt {
447
+ type: "rollback";
448
+ savepoint: string | null;
449
+ }
450
+ export interface SavepointStmt {
451
+ type: "savepoint";
452
+ name: string;
453
+ }
454
+ export interface ReleaseStmt {
455
+ type: "release";
456
+ name: string;
457
+ }
458
+ export interface PragmaStmt {
459
+ type: "pragma";
460
+ name: string;
461
+ value: Expr | null;
462
+ }
463
+ export interface AttachStmt {
464
+ type: "attach";
465
+ filename: Expr;
466
+ schema: string;
467
+ }
468
+ export interface DetachStmt {
469
+ type: "detach";
470
+ schema: string;
471
+ }
472
+ export interface ExplainStmt {
473
+ type: "explain";
474
+ queryPlan: boolean;
475
+ statement: Statement;
476
+ }
@@ -0,0 +1,11 @@
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 { Table } from "../storage/table.js";
5
+ import type { SqlValue } from "../types/value.js";
6
+ export type CheckEvaluator = (expr: Expr, row: Row) => SqlValue;
7
+ export declare function checkNotNull(table: Table, row: Row): void;
8
+ export declare function checkPrimaryKey(table: Table, row: Row): void;
9
+ export declare function checkUnique(index: IndexStore, values: readonly SqlValue[], rowid?: Rowid): void;
10
+ export declare function checkExpressions(expressions: readonly Expr[], row: Row, evaluate: CheckEvaluator, constraintName?: string): void;
11
+ export declare function checkTableConstraints(table: Table, row: Row, evaluate: CheckEvaluator): void;