@crvouga/sqlite-mem 1.10.0 → 1.12.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/dist/index.js +4180 -3869
- package/dist/index.js.map +4 -4
- package/dist/indexes/index.d.ts +2 -0
- package/dist/serialization/codec.d.ts +3 -11
- package/dist/serialization/wire.d.ts +61 -0
- package/dist/storage/columnar-slab.d.ts +58 -0
- package/dist/storage/table.d.ts +13 -0
- package/dist/unstable.js +842 -547
- package/dist/unstable.js.map +4 -4
- package/package.json +1 -1
package/dist/indexes/index.d.ts
CHANGED
|
@@ -34,6 +34,8 @@ export declare class IndexStore {
|
|
|
34
34
|
rowids: Rowid[];
|
|
35
35
|
}>;
|
|
36
36
|
rememberKeyValues(key: string, values: readonly SqlValue[]): void;
|
|
37
|
+
/** Key component values for snapshot encode (binary keys). */
|
|
38
|
+
keyValuesFor(key: string): SqlValue[];
|
|
37
39
|
get size(): number;
|
|
38
40
|
private orderedKeys;
|
|
39
41
|
private assertMutable;
|
|
@@ -1,27 +1,19 @@
|
|
|
1
1
|
import { DatabaseState } from "../storage/database-state.js";
|
|
2
|
-
/** PRNG + clock captured alongside schema/rows
|
|
2
|
+
/** PRNG + clock captured alongside schema/rows. */
|
|
3
3
|
export interface SnapshotRuntime {
|
|
4
|
-
/** Unsigned 64-bit {@link Prng} state. */
|
|
5
4
|
prngState: bigint;
|
|
6
|
-
/** Clock instant as milliseconds since Unix epoch. */
|
|
7
5
|
nowMs: number;
|
|
8
6
|
}
|
|
9
7
|
/** Result of {@link decodeDatabaseState}. */
|
|
10
8
|
export interface DecodedSnapshot {
|
|
11
|
-
/** Restored catalog and table data. */
|
|
12
9
|
state: DatabaseState;
|
|
13
|
-
|
|
14
|
-
runtime: SnapshotRuntime | null;
|
|
10
|
+
runtime: SnapshotRuntime;
|
|
15
11
|
}
|
|
16
12
|
/**
|
|
17
13
|
* Encode catalog, rows, and runtime into a sqlite-mem snapshot blob (not a `.sqlite` file).
|
|
18
|
-
*
|
|
19
|
-
* Prefer {@link Database.snapshot} unless you are serializing engine state directly.
|
|
20
14
|
*/
|
|
21
|
-
export declare function encodeDatabaseState(state: DatabaseState, runtime: SnapshotRuntime
|
|
15
|
+
export declare function encodeDatabaseState(state: DatabaseState, runtime: SnapshotRuntime): Uint8Array;
|
|
22
16
|
/**
|
|
23
17
|
* Decode a blob from {@link encodeDatabaseState} / {@link Database.snapshot}.
|
|
24
|
-
*
|
|
25
|
-
* @throws {SqliteError} If the magic, version, or payload is invalid.
|
|
26
18
|
*/
|
|
27
19
|
export declare function decodeDatabaseState(snapshot: Uint8Array): DecodedSnapshot;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export declare function writeVarintU32(w: Writer, value: number): void;
|
|
2
|
+
export declare function readVarintU32(r: Reader): number;
|
|
3
|
+
export declare class Writer {
|
|
4
|
+
private buf;
|
|
5
|
+
private view;
|
|
6
|
+
private len;
|
|
7
|
+
constructor(capacity?: number);
|
|
8
|
+
get position(): number;
|
|
9
|
+
reserve(capacity: number): void;
|
|
10
|
+
private ensure;
|
|
11
|
+
align4(): void;
|
|
12
|
+
u8(value: number): void;
|
|
13
|
+
u32(value: number): void;
|
|
14
|
+
u64(value: bigint): void;
|
|
15
|
+
i64(value: bigint): void;
|
|
16
|
+
f64(value: number): void;
|
|
17
|
+
raw(value: Uint8Array): void;
|
|
18
|
+
rawAt(offset: number, value: Uint8Array): void;
|
|
19
|
+
/** Length-prefixed UTF-8 via encodeInto when possible. */
|
|
20
|
+
text(value: string): void;
|
|
21
|
+
/** Write UTF-8 at current position without length prefix (intern blob region). */
|
|
22
|
+
textBytes(value: string): void;
|
|
23
|
+
finish(): Uint8Array;
|
|
24
|
+
fail(): never;
|
|
25
|
+
}
|
|
26
|
+
export declare class Reader {
|
|
27
|
+
private readonly bytes;
|
|
28
|
+
private offset;
|
|
29
|
+
private readonly view;
|
|
30
|
+
constructor(bytes: Uint8Array);
|
|
31
|
+
get position(): number;
|
|
32
|
+
skipAlign4(): void;
|
|
33
|
+
u8(): number;
|
|
34
|
+
u32(): number;
|
|
35
|
+
u64(): bigint;
|
|
36
|
+
i64(): bigint;
|
|
37
|
+
f64(): number;
|
|
38
|
+
raw(length: number): Uint8Array;
|
|
39
|
+
text(): string;
|
|
40
|
+
remaining(): number;
|
|
41
|
+
done(): boolean;
|
|
42
|
+
fail(): never;
|
|
43
|
+
}
|
|
44
|
+
export declare function writeBjv(w: Writer, value: unknown, forceIntern: (s: string) => number): void;
|
|
45
|
+
export declare function readBjv(r: Reader, intern: readonly string[]): unknown;
|
|
46
|
+
export declare class InternPool {
|
|
47
|
+
private readonly counts;
|
|
48
|
+
private readonly ids;
|
|
49
|
+
readonly list: string[];
|
|
50
|
+
constructor();
|
|
51
|
+
count(s: string): void;
|
|
52
|
+
/** Assign ids only to strings seen ≥2 times (plus empty string). */
|
|
53
|
+
finalize(): void;
|
|
54
|
+
/** Always intern (schema / catalog strings). */
|
|
55
|
+
forceId(s: string): number;
|
|
56
|
+
id(s: string): number;
|
|
57
|
+
has(s: string): boolean;
|
|
58
|
+
}
|
|
59
|
+
/** Write intern table: count, offsets[], concatenated UTF-8 blob. */
|
|
60
|
+
export declare function writeInternTable(w: Writer, strings: readonly string[]): void;
|
|
61
|
+
export declare function readInternTable(r: Reader): string[];
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type SqlValue } from "../types/value.js";
|
|
2
|
+
import type { Rowid } from "./row.js";
|
|
3
|
+
/** Column pack tags (SQLM v5). */
|
|
4
|
+
export declare const PACK_NULL = 0;
|
|
5
|
+
export declare const PACK_I32 = 1;
|
|
6
|
+
export declare const PACK_I64 = 2;
|
|
7
|
+
export declare const PACK_F64 = 3;
|
|
8
|
+
export declare const PACK_TEXT_INTERN = 4;
|
|
9
|
+
export declare const PACK_TEXT_INLINE = 5;
|
|
10
|
+
export declare const PACK_BLOB = 6;
|
|
11
|
+
export declare const PACK_TAGGED = 7;
|
|
12
|
+
export interface SlabColumn {
|
|
13
|
+
pack: number;
|
|
14
|
+
nullBitmap: Uint8Array | null;
|
|
15
|
+
/** Typed payload or inline blob region inside `buffer`. */
|
|
16
|
+
payload: Uint8Array;
|
|
17
|
+
/** Cached view over `payload` (avoid per-cell DataView alloc). */
|
|
18
|
+
view?: DataView;
|
|
19
|
+
/** Prefix count of non-null cells before each row (when nulls exist). */
|
|
20
|
+
nonNullRank?: Uint32Array;
|
|
21
|
+
/** For PACK_TEXT_INLINE: u32 offsets into payload per row. */
|
|
22
|
+
inlineOffsets?: Uint32Array;
|
|
23
|
+
/** For PACK_TAGGED: decoded values per non-null row in order. */
|
|
24
|
+
tagged?: SqlValue[];
|
|
25
|
+
/** For PACK_BLOB: one entry per non-null row. */
|
|
26
|
+
blobChunks?: Uint8Array[];
|
|
27
|
+
}
|
|
28
|
+
/** Attach decode helpers; drop an all-zero null bitmap. */
|
|
29
|
+
export declare function prepareSlabColumn(column: SlabColumn, rowCount: number, nonNull: number): SlabColumn;
|
|
30
|
+
/** Frozen columnar row storage; zero-copy views into snapshot buffer. */
|
|
31
|
+
export declare class ColumnarSlab {
|
|
32
|
+
readonly buffer: Uint8Array;
|
|
33
|
+
readonly rowCount: number;
|
|
34
|
+
readonly rowids: Rowid[];
|
|
35
|
+
readonly columns: SlabColumn[];
|
|
36
|
+
private readonly intern;
|
|
37
|
+
private rowidIndex;
|
|
38
|
+
constructor(buffer: Uint8Array, rowCount: number, rowids: Rowid[], columns: SlabColumn[], intern: readonly string[]);
|
|
39
|
+
private rowIndex;
|
|
40
|
+
cell(rowIndex: number, col: number): SqlValue;
|
|
41
|
+
rowAt(rowIndex: number): {
|
|
42
|
+
rowid: Rowid;
|
|
43
|
+
values: SqlValue[];
|
|
44
|
+
};
|
|
45
|
+
get(rowid: Rowid): {
|
|
46
|
+
rowid: Rowid;
|
|
47
|
+
values: SqlValue[];
|
|
48
|
+
} | undefined;
|
|
49
|
+
scan(): Generator<{
|
|
50
|
+
rowid: Rowid;
|
|
51
|
+
values: SqlValue[];
|
|
52
|
+
}>;
|
|
53
|
+
materialize(): Map<Rowid, {
|
|
54
|
+
rowid: Rowid;
|
|
55
|
+
values: SqlValue[];
|
|
56
|
+
}>;
|
|
57
|
+
}
|
|
58
|
+
export declare function packKindOf(value: SqlValue): number;
|
package/dist/storage/table.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Expr, TableConstraint } from "../ast/nodes.js";
|
|
2
2
|
import type { Affinity, SqlValue } from "../types/value.js";
|
|
3
3
|
import type { Row, Rowid, RowValues } from "./row.js";
|
|
4
|
+
import type { ColumnarSlab } from "./columnar-slab.js";
|
|
4
5
|
export interface ColumnInfo {
|
|
5
6
|
name: string;
|
|
6
7
|
/** Cached `name.toLowerCase()` for hot-path lookups. */
|
|
@@ -49,6 +50,8 @@ export declare class Table {
|
|
|
49
50
|
strict: boolean;
|
|
50
51
|
/** Clustered PK key string → row for WITHOUT ROWID tables. */
|
|
51
52
|
clusteredRows: Map<string, Row>;
|
|
53
|
+
/** Frozen columnar storage after snapshot hydrate; `rows` stays empty until materialized. */
|
|
54
|
+
slab: ColumnarSlab | null;
|
|
52
55
|
private scanCache;
|
|
53
56
|
/** Lazy covering hashes: column nameLower → serializeIndexKey → rowids. */
|
|
54
57
|
private equalityHashes;
|
|
@@ -67,6 +70,16 @@ export declare class Table {
|
|
|
67
70
|
rowFromNamed(values: Map<string, SqlValue>, rowid?: Rowid): Row;
|
|
68
71
|
integerPkColumn(): ColumnInfo | undefined;
|
|
69
72
|
get(rowid: Rowid): Row | undefined;
|
|
73
|
+
/** Row count (slab-backed or map-backed). */
|
|
74
|
+
rowCount(): number;
|
|
75
|
+
/** Rows sorted by rowid for snapshot encode. */
|
|
76
|
+
sortedRows(): Row[];
|
|
77
|
+
/** Attach decoded columnar slab (hydrate path). */
|
|
78
|
+
attachSlab(slab: ColumnarSlab): void;
|
|
79
|
+
/** Materialize slab into `rows` Map for mutation. */
|
|
80
|
+
materializeSlab(): void;
|
|
81
|
+
private hasRow;
|
|
82
|
+
private allRowids;
|
|
70
83
|
getByKey(value: SqlValue): Row | undefined;
|
|
71
84
|
private invalidateScan;
|
|
72
85
|
private commitRow;
|