@yydb/sqlite 0.0.12 → 0.1.6
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/package.json +9 -9
- package/src/node.ts +80 -26
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yydb/sqlite",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Bounded read-only SQLite format-3 snapshot reader,
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"description": "Bounded read-only SQLite format-3 snapshot reader for YYDB — schema inspection, typed record decoding, and blank database creation.",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"bin": {
|
|
21
|
-
"
|
|
21
|
+
"sqlite": "bin/sqlite3.mjs"
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
24
24
|
"bin",
|
|
@@ -31,24 +31,24 @@
|
|
|
31
31
|
},
|
|
32
32
|
"repository": {
|
|
33
33
|
"type": "git",
|
|
34
|
-
"url": "git+https://github.com/yy-database/
|
|
34
|
+
"url": "git+https://github.com/yy-database/yydb.git",
|
|
35
35
|
"directory": "projects/packages/sqlite"
|
|
36
36
|
},
|
|
37
|
-
"homepage": "https://github.com/yy-database/
|
|
37
|
+
"homepage": "https://github.com/yy-database/yydb/tree/dev/projects/packages/sqlite#readme",
|
|
38
38
|
"bugs": {
|
|
39
|
-
"url": "https://github.com/yy-database/
|
|
39
|
+
"url": "https://github.com/yy-database/yydb/issues"
|
|
40
40
|
},
|
|
41
41
|
"keywords": [
|
|
42
|
-
"
|
|
42
|
+
"yydb",
|
|
43
43
|
"sqlite",
|
|
44
|
-
"
|
|
44
|
+
"format-3",
|
|
45
45
|
"binary-compatible"
|
|
46
46
|
],
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@yydb/
|
|
51
|
+
"@yydb/yydb": "0.1.6"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@types/node": "^22.15.0",
|
package/src/node.ts
CHANGED
|
@@ -1,27 +1,81 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
import { loadNative } from "@yydb/yydb";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SQLite read-only binding types — declared locally since yydb-napi does not
|
|
5
|
+
* re-export them through the TS facade. The actual implementations live in
|
|
6
|
+
* the same native `.node` file loaded by `@yydb/yydb`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export interface SqliteReadLimits {
|
|
10
|
+
maxPages?: number;
|
|
11
|
+
maxRows?: number;
|
|
12
|
+
maxPayloadBytes?: number;
|
|
13
|
+
maxTotalPayloadBytes?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface SqliteSchemaObject {
|
|
17
|
+
kind: string;
|
|
18
|
+
name: string;
|
|
19
|
+
tableName: string;
|
|
20
|
+
rootPage: number | null;
|
|
21
|
+
sql: string | null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface SqliteTableRow {
|
|
25
|
+
rowid: number;
|
|
26
|
+
payload: Buffer;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface SqliteRecordValue {
|
|
30
|
+
kind: string;
|
|
31
|
+
valueInteger?: number | null;
|
|
32
|
+
valueReal?: number | null;
|
|
33
|
+
valueText?: string | null;
|
|
34
|
+
valueBlob?: Buffer | null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface SqliteDecodedRow {
|
|
38
|
+
rowid: number;
|
|
39
|
+
columns: SqliteRecordValue[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface SqliteSnapshotBinding {
|
|
43
|
+
schema(limits?: SqliteReadLimits): SqliteSchemaObject[];
|
|
44
|
+
table(name: string, limits?: SqliteReadLimits): SqliteTableRow[];
|
|
45
|
+
tableDecoded(name: string, limits?: SqliteReadLimits): SqliteDecodedRow[];
|
|
46
|
+
sqliteVersion(): string;
|
|
47
|
+
encoding(): string;
|
|
48
|
+
ping(): number;
|
|
49
|
+
pages(): Buffer;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface SqliteDatabaseBinding {
|
|
53
|
+
openInMemory(): SqliteDatabaseBinding;
|
|
54
|
+
open(path: string): SqliteDatabaseBinding;
|
|
55
|
+
path(): string | null;
|
|
56
|
+
ping(): number;
|
|
57
|
+
sqliteVersion(): string;
|
|
58
|
+
encoding(): string;
|
|
59
|
+
schema(limits?: SqliteReadLimits): SqliteSchemaObject[];
|
|
60
|
+
table(name: string, limits?: SqliteReadLimits): SqliteDecodedRow[];
|
|
61
|
+
tableRaw(name: string, limits?: SqliteReadLimits): SqliteTableRow[];
|
|
62
|
+
pages(): Buffer;
|
|
63
|
+
}
|
|
64
|
+
|
|
23
65
|
export type SqliteTextEncoding = "utf8" | "utf16le" | "utf16be";
|
|
24
66
|
|
|
67
|
+
function loadSqliteNative() {
|
|
68
|
+
const native = loadNative() as Record<string, unknown>;
|
|
69
|
+
if (typeof native.SqliteSnapshot !== "function") {
|
|
70
|
+
throw new Error("Native addon lacks the SQLite snapshot reader. Rebuild the native package.");
|
|
71
|
+
}
|
|
72
|
+
return native as unknown as {
|
|
73
|
+
SqliteSnapshot: new (bytes: Buffer, maxSnapshotBytes: number) => SqliteSnapshotBinding;
|
|
74
|
+
SqliteDatabase: { openInMemory(): SqliteDatabaseBinding; open(path: string): SqliteDatabaseBinding };
|
|
75
|
+
decodeRecord: (payload: Buffer, encoding?: string) => SqliteRecordValue[];
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
25
79
|
/** Read-only, copied main-file bytes. WAL/journal recovery is not performed. */
|
|
26
80
|
export class SqliteSnapshot {
|
|
27
81
|
readonly #native: SqliteSnapshotBinding;
|
|
@@ -34,7 +88,7 @@ export class SqliteSnapshot {
|
|
|
34
88
|
if (bytes.byteLength > maxSnapshotBytes) {
|
|
35
89
|
throw new RangeError("sqlite snapshot byte limit exceeded");
|
|
36
90
|
}
|
|
37
|
-
const native =
|
|
91
|
+
const native = loadSqliteNative();
|
|
38
92
|
this.#native = new native.SqliteSnapshot(Buffer.from(bytes), maxSnapshotBytes);
|
|
39
93
|
}
|
|
40
94
|
|
|
@@ -95,7 +149,7 @@ export class SqliteDatabase {
|
|
|
95
149
|
|
|
96
150
|
/** Opens a blank in-memory SQLite format-3 snapshot. */
|
|
97
151
|
static openInMemory(): SqliteDatabase {
|
|
98
|
-
const native =
|
|
152
|
+
const native = loadSqliteNative();
|
|
99
153
|
return new SqliteDatabase(native.SqliteDatabase.openInMemory());
|
|
100
154
|
}
|
|
101
155
|
|
|
@@ -104,7 +158,7 @@ export class SqliteDatabase {
|
|
|
104
158
|
if (typeof path !== "string" || path.length === 0) {
|
|
105
159
|
throw new TypeError("SQLite path must be a non-empty string");
|
|
106
160
|
}
|
|
107
|
-
const native =
|
|
161
|
+
const native = loadSqliteNative();
|
|
108
162
|
return new SqliteDatabase(native.SqliteDatabase.open(path));
|
|
109
163
|
}
|
|
110
164
|
|
|
@@ -169,7 +223,7 @@ export function decodeRecord(
|
|
|
169
223
|
if (!(payload instanceof Uint8Array)) {
|
|
170
224
|
throw new TypeError("payload must be a Uint8Array or Buffer");
|
|
171
225
|
}
|
|
172
|
-
const native =
|
|
226
|
+
const native = loadSqliteNative();
|
|
173
227
|
const encArg: string | undefined =
|
|
174
228
|
encoding === undefined ? undefined : encoding;
|
|
175
229
|
return native.decodeRecord(Buffer.from(payload), encArg);
|