@crvouga/sqlite-mem 1.1.1 → 1.2.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.
- package/AGENTS.md +4 -1
- package/COMPATIBILITY-AUDIT.md +29 -15
- package/COMPATIBILITY.md +16 -8
- package/README.md +17 -12
- package/compat/coverage.json +779 -729
- package/compat/divergences.json +124 -0
- package/compat/requirements.json +43 -43
- package/compat/scenario-types.ts +63 -0
- package/compat/scenarios.ts +851 -0
- package/compat/smoke-baseline.json +15 -0
- package/dist/api/database.d.ts +12 -3
- package/dist/api/statement.d.ts +1 -1
- package/dist/ast/nodes.d.ts +12 -1
- package/dist/executor/env.d.ts +1 -1
- package/dist/executor/select.d.ts +2 -1
- package/dist/executor/triggers.d.ts +2 -2
- package/dist/expressions/context.d.ts +3 -1
- package/dist/expressions/like.d.ts +3 -2
- package/dist/functions/registry.d.ts +2 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +698 -187
- package/dist/index.js.map +4 -4
- package/dist/lexer/tokenize.d.ts +1 -1
- package/dist/parser/parser.d.ts +2 -2
- package/dist/runtime/clock.d.ts +4 -2
- package/dist/runtime/index.d.ts +3 -3
- package/dist/runtime/options.d.ts +11 -3
- package/dist/runtime/prng.d.ts +11 -0
- package/dist/storage/database-state.d.ts +2 -0
- package/dist/storage/table.d.ts +2 -0
- package/dist/types/value.d.ts +5 -0
- package/dist/unstable.d.ts +3 -3
- package/dist/unstable.js +266 -64
- package/dist/unstable.js.map +3 -3
- package/dist/vtable/fts/table.d.ts +2 -3
- package/package.json +5 -2
package/dist/api/database.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type DatabaseOptions } from "../runtime/index.js";
|
|
1
|
+
import { type DatabaseOptions, type RandomMode } from "../runtime/index.js";
|
|
2
2
|
import type { BindValue, QueryRow } from "../types/value.js";
|
|
3
3
|
import { Statement } from "./statement.js";
|
|
4
4
|
/**
|
|
@@ -6,7 +6,8 @@ import { Statement } from "./statement.js";
|
|
|
6
6
|
*
|
|
7
7
|
* Deterministic by default: `random()` / `randomblob()` use a seeded PRNG
|
|
8
8
|
* (`seed` defaults to `1`) and `date('now')` / friends use a fixed clock
|
|
9
|
-
* (`2000-01-01T00:00:00.000Z`).
|
|
9
|
+
* (`2000-01-01T00:00:00.000Z`). Pass `{ random: "os" }` and `{ now: "system" }`
|
|
10
|
+
* for SQLite-like CSPRNG and wall-clock `'now'`. There is no filesystem or WASM.
|
|
10
11
|
*
|
|
11
12
|
* @example
|
|
12
13
|
* ```ts
|
|
@@ -19,8 +20,10 @@ import { Statement } from "./statement.js";
|
|
|
19
20
|
* ```
|
|
20
21
|
*/
|
|
21
22
|
export declare class Database {
|
|
22
|
-
/** Seed used to construct the PRNG. */
|
|
23
|
+
/** Seed used to construct the PRNG. Ignored when {@link randomMode} is `"os"`. */
|
|
23
24
|
readonly seed: number | bigint;
|
|
25
|
+
/** Entropy mode for `random()` / `randomblob()`. */
|
|
26
|
+
readonly randomMode: RandomMode;
|
|
24
27
|
private closed;
|
|
25
28
|
private transactionSequence;
|
|
26
29
|
/** Depth of active {@link transaction} callbacks (not SQL BEGIN). */
|
|
@@ -106,6 +109,12 @@ export declare class Database {
|
|
|
106
109
|
* @throws {SqliteError} If the database is closed.
|
|
107
110
|
*/
|
|
108
111
|
get lastInsertRowid(): number | bigint;
|
|
112
|
+
/**
|
|
113
|
+
* Cumulative rows changed by INSERT / UPDATE / DELETE (SQLite `total_changes()`).
|
|
114
|
+
*
|
|
115
|
+
* @throws {SqliteError} If the database is closed.
|
|
116
|
+
*/
|
|
117
|
+
get totalChanges(): number;
|
|
109
118
|
private prepareSingle;
|
|
110
119
|
}
|
|
111
120
|
export type { DatabaseOptions };
|
package/dist/api/statement.d.ts
CHANGED
package/dist/ast/nodes.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ 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
4
|
/** Parsed SQL expression AST (literals, operators, functions, subqueries, …). */
|
|
5
|
-
export type Expr = LiteralExpr | NullExpr | ColumnRefExpr | UnaryExpr | BinaryExpr | BetweenExpr | InExpr | LikeExpr | FunctionExpr | AggregateExpr | WindowExpr | CaseExpr | CastExpr | ExistsExpr | SubqueryExpr | ParameterExpr | RowExpr | CollateExpr;
|
|
5
|
+
export type Expr = LiteralExpr | NullExpr | ColumnRefExpr | UnaryExpr | BinaryExpr | BetweenExpr | InExpr | LikeExpr | IsBoolExpr | FunctionExpr | AggregateExpr | WindowExpr | CaseExpr | CastExpr | ExistsExpr | SubqueryExpr | ParameterExpr | RowExpr | CollateExpr;
|
|
6
6
|
export interface LiteralExpr {
|
|
7
7
|
type: "literal";
|
|
8
8
|
value: SqlValue;
|
|
@@ -28,6 +28,14 @@ export interface BinaryExpr {
|
|
|
28
28
|
left: Expr;
|
|
29
29
|
right: Expr;
|
|
30
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
|
+
}
|
|
31
39
|
export interface BetweenExpr {
|
|
32
40
|
type: "between";
|
|
33
41
|
not: boolean;
|
|
@@ -54,6 +62,7 @@ export interface FunctionExpr {
|
|
|
54
62
|
name: string;
|
|
55
63
|
distinct: boolean;
|
|
56
64
|
args: Expr[] | "*";
|
|
65
|
+
orderBy: OrderByItem[];
|
|
57
66
|
filter: Expr | null;
|
|
58
67
|
}
|
|
59
68
|
export interface AggregateExpr {
|
|
@@ -61,6 +70,7 @@ export interface AggregateExpr {
|
|
|
61
70
|
name: string;
|
|
62
71
|
distinct: boolean;
|
|
63
72
|
args: Expr[] | "*";
|
|
73
|
+
orderBy: OrderByItem[];
|
|
64
74
|
filter: Expr | null;
|
|
65
75
|
}
|
|
66
76
|
export interface WindowExpr {
|
|
@@ -184,6 +194,7 @@ export interface WithClause {
|
|
|
184
194
|
export interface Cte {
|
|
185
195
|
name: string;
|
|
186
196
|
columns: string[] | null;
|
|
197
|
+
materialized: "materialized" | "not_materialized" | null;
|
|
187
198
|
select: SelectStmt;
|
|
188
199
|
}
|
|
189
200
|
export type ResultColumn = {
|
package/dist/executor/env.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { type FunctionRegistry } from "../functions/registry.js";
|
|
|
4
4
|
import type { DatabaseState } from "../storage/database-state.js";
|
|
5
5
|
import type { Rowid } from "../storage/row.js";
|
|
6
6
|
import type { TransactionManager } from "../transactions/manager.js";
|
|
7
|
-
import type { ResultSet } from "./result.js";
|
|
8
7
|
import { type Affinity, type SqlValue } from "../types/value.js";
|
|
8
|
+
import type { ResultSet } from "./result.js";
|
|
9
9
|
export interface Cell {
|
|
10
10
|
table: string | null;
|
|
11
11
|
tableLower?: string | null;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { FromItem, SelectStmt } from "../ast/nodes.js";
|
|
1
|
+
import type { FromItem, SelectStmt, WithClause } from "../ast/nodes.js";
|
|
2
2
|
import type { EvalContext } from "../expressions/context.js";
|
|
3
3
|
import type { ExecutionEnv, ScopeRow } from "./env.js";
|
|
4
4
|
import { type ResultSet } from "./result.js";
|
|
5
5
|
export declare function executeSelect(stmt: SelectStmt, env: ExecutionEnv, parent?: EvalContext): ResultSet;
|
|
6
|
+
export declare function executeWith(withClause: WithClause, env: ExecutionEnv, parent?: EvalContext): void;
|
|
6
7
|
export declare function scanFrom(item: FromItem, env: ExecutionEnv, parent?: EvalContext): ScopeRow[];
|
|
@@ -7,5 +7,5 @@ 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
|
-
export declare function fireUpdateTriggers(timing: "BEFORE" | "AFTER", table: Table, oldRow: Row, newValues: Map<string, SqlValue>, updatedColumns: Set<string>, env: ExecutionEnv): "ok" | "ignore";
|
|
11
|
-
export declare function fireDeleteTriggers(timing: "BEFORE" | "AFTER", table: Table, oldRow: Row, env: ExecutionEnv): "ok" | "ignore";
|
|
10
|
+
export declare function fireUpdateTriggers(timing: "BEFORE" | "AFTER" | "INSTEAD", table: Table, oldRow: Row, newValues: Map<string, SqlValue>, updatedColumns: Set<string>, env: ExecutionEnv): "ok" | "ignore";
|
|
11
|
+
export declare function fireDeleteTriggers(timing: "BEFORE" | "AFTER" | "INSTEAD", table: Table, oldRow: Row, env: ExecutionEnv): "ok" | "ignore";
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { SelectStmt } from "../ast/nodes.js";
|
|
2
2
|
import type { FunctionContext, FunctionRegistry } from "../functions/registry.js";
|
|
3
|
-
import type { SqlValue, StorageClass } from "../types/value.js";
|
|
3
|
+
import type { Affinity, SqlValue, StorageClass } from "../types/value.js";
|
|
4
4
|
import type { FtsMatchCursor } from "../vtable/fts5.js";
|
|
5
5
|
/** Column / parameter / function resolution used by {@link evalExpr}. */
|
|
6
6
|
export interface EvalContext {
|
|
7
7
|
resolveColumn(table: string | null, name: string): SqlValue;
|
|
8
8
|
resolveStorageClass?(table: string | null, name: string): StorageClass;
|
|
9
|
+
/** Declared column affinity when available (for comparisons). */
|
|
10
|
+
resolveAffinity?(table: string | null, name: string): Affinity | null;
|
|
9
11
|
/** Declared column collation when available (for inheritance). */
|
|
10
12
|
resolveCollation?(table: string | null, name: string): string | null;
|
|
11
13
|
getParameter(name: string | number): SqlValue;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* SQLite LIKE matching. ASCII letters are case-insensitive
|
|
2
|
+
* SQLite LIKE matching. ASCII letters are case-insensitive unless `caseSensitive`.
|
|
3
3
|
*
|
|
4
4
|
* @param text - Value to test.
|
|
5
5
|
* @param pattern - Pattern with `%` / `_` wildcards.
|
|
6
6
|
* @param escape - Optional single-character ESCAPE (or `null`).
|
|
7
|
+
* @param caseSensitive - When true, match like GLOB (SQLite `PRAGMA case_sensitive_like=ON`).
|
|
7
8
|
*/
|
|
8
|
-
export declare function likeMatch(text: string, pattern: string, escape?: string | null): boolean;
|
|
9
|
+
export declare function likeMatch(text: string, pattern: string, escape?: string | null, caseSensitive?: boolean): boolean;
|
|
9
10
|
/**
|
|
10
11
|
* SQLite GLOB matching. GLOB is case-sensitive and uses Unix `*` / `?` wildcards.
|
|
11
12
|
*
|
|
@@ -12,6 +12,8 @@ export interface FunctionContext {
|
|
|
12
12
|
randomU64?: () => bigint;
|
|
13
13
|
/** Active FTS MATCH cursor when evaluating projections with MATCH in WHERE. */
|
|
14
14
|
ftsMatch?: import("../vtable/fts5.js").FtsMatchCursor | null;
|
|
15
|
+
/** SQLite `PRAGMA case_sensitive_like` for LIKE / like(). */
|
|
16
|
+
caseSensitiveLike?: boolean;
|
|
15
17
|
/** Current rowid for FTS aux defaults when MATCH is absent. */
|
|
16
18
|
ftsRowid?: import("../storage/row.js").Rowid;
|
|
17
19
|
/** Source FTS table name for the current scan row. */
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Pure TypeScript in-memory SQLite. Import {@link Database} to get started.
|
|
4
4
|
*
|
|
5
5
|
* Deterministic by default (`random()` seed `1`, `'now'` = `2000-01-01T00:00:00.000Z`).
|
|
6
|
+
* Pass `{ random: "os" }` / `{ now: "system" }` for SQLite-like entropy and wall clock.
|
|
6
7
|
* Zero WASM, native bindings, or filesystem.
|
|
7
8
|
*
|
|
8
9
|
* Advanced / internal helpers live under `@crvouga/sqlite-mem/unstable` and are
|
|
@@ -21,7 +22,7 @@
|
|
|
21
22
|
* @module
|
|
22
23
|
*/
|
|
23
24
|
export { Database, type DatabaseOptions } from "./api/database.js";
|
|
24
|
-
export {
|
|
25
|
-
export {
|
|
25
|
+
export { type RunResult, Statement } from "./api/statement.js";
|
|
26
|
+
export { type ErrorCategory, SqliteError } from "./errors/index.js";
|
|
26
27
|
export type { ResultSet } from "./executor/result.js";
|
|
27
28
|
export type { BindValue, QueryRow, QueryValue } from "./types/value.js";
|