@lix-js/sdk 0.1.0 → 0.3.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/account/database-schema.d.ts.map +1 -1
- package/dist/account/database-schema.js +2 -6
- package/dist/account/database-schema.js.map +1 -1
- package/dist/account/database-schema.test.js +4 -8
- package/dist/account/database-schema.test.js.map +1 -1
- package/dist/database/apply-schema.js +2 -2
- package/dist/database/init-db.test.js +3 -3
- package/dist/database/init-db.test.js.map +1 -1
- package/dist/file-queue/file-queue-process.d.ts.map +1 -1
- package/dist/file-queue/file-queue-process.js +4 -1
- package/dist/file-queue/file-queue-process.js.map +1 -1
- package/dist/file-queue/file-queue-process.test.js +4 -5
- package/dist/file-queue/file-queue-process.test.js.map +1 -1
- package/dist/lix/open-lix.d.ts +16 -1
- package/dist/lix/open-lix.d.ts.map +1 -1
- package/dist/lix/open-lix.js +76 -0
- package/dist/lix/open-lix.js.map +1 -1
- package/dist/lix/open-lix.test.js +54 -0
- package/dist/lix/open-lix.test.js.map +1 -1
- package/dist/query-filter/change-has-label.d.ts +2 -2
- package/dist/query-filter/change-has-label.js +2 -2
- package/dist/query-filter/change-set-has-label.d.ts +2 -2
- package/dist/query-filter/change-set-has-label.js +2 -2
- package/dist/services/env-variables/index.d.ts +5 -0
- package/dist/services/env-variables/index.d.ts.map +1 -0
- package/dist/services/env-variables/index.js +5 -0
- package/dist/services/env-variables/index.js.map +1 -0
- package/dist/services/telemetry/capture.d.ts +30 -0
- package/dist/services/telemetry/capture.d.ts.map +1 -0
- package/dist/services/telemetry/capture.js +71 -0
- package/dist/services/telemetry/capture.js.map +1 -0
- package/dist/services/telemetry/capture.test.d.ts +2 -0
- package/dist/services/telemetry/capture.test.d.ts.map +1 -0
- package/dist/services/telemetry/capture.test.js +37 -0
- package/dist/services/telemetry/capture.test.js.map +1 -0
- package/dist/sync/sync-process.d.ts.map +1 -1
- package/dist/sync/sync-process.js +11 -5
- package/dist/sync/sync-process.js.map +1 -1
- package/package.json +4 -6
- package/src/account/database-schema.test.ts +6 -9
- package/src/account/database-schema.ts +2 -6
- package/src/database/apply-schema.ts +2 -2
- package/src/database/init-db.test.ts +3 -3
- package/src/file-queue/file-queue-process.test.ts +4 -5
- package/src/file-queue/file-queue-process.ts +4 -1
- package/src/lix/open-lix.test.ts +63 -0
- package/src/lix/open-lix.ts +98 -1
- package/src/query-filter/change-has-label.ts +2 -2
- package/src/query-filter/change-set-has-label.ts +2 -2
- package/src/services/env-variables/create-index-file.js +35 -0
- package/src/services/env-variables/index.d.ts +15 -0
- package/src/services/telemetry/capture.test.ts +44 -0
- package/src/services/telemetry/capture.ts +99 -0
- package/src/sync/sync-process.ts +11 -6
- package/node_modules/@lix-js/server-api-schema/.prettierrc.json +0 -3
- package/node_modules/@lix-js/server-api-schema/.vscode/extensions.json +0 -3
- package/node_modules/@lix-js/server-api-schema/CHANGELOG.md +0 -9
- package/node_modules/@lix-js/server-api-schema/LICENSE +0 -21
- package/node_modules/@lix-js/server-api-schema/dist/schema.js +0 -0
- package/node_modules/@lix-js/server-api-schema/package.json +0 -21
- package/node_modules/@lix-js/server-api-schema/src/schema.yaml +0 -290
- package/node_modules/@lix-js/server-api-schema/tsconfig.json +0 -20
- package/node_modules/sqlite-wasm-kysely/LICENSE +0 -21
- package/node_modules/sqlite-wasm-kysely/README.md +0 -11
- package/node_modules/sqlite-wasm-kysely/dist/dialect.d.ts +0 -11
- package/node_modules/sqlite-wasm-kysely/dist/dialect.js +0 -13
- package/node_modules/sqlite-wasm-kysely/dist/dialect.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/index.d.ts +0 -2
- package/node_modules/sqlite-wasm-kysely/dist/index.js +0 -3
- package/node_modules/sqlite-wasm-kysely/dist/index.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/kysely/ConnectionMutex.d.ts +0 -5
- package/node_modules/sqlite-wasm-kysely/dist/kysely/ConnectionMutex.js +0 -34
- package/node_modules/sqlite-wasm-kysely/dist/kysely/ConnectionMutex.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmConnection.d.ts +0 -8
- package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmConnection.js +0 -57
- package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmConnection.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmDialectConfig.d.ts +0 -18
- package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmDialectConfig.js +0 -2
- package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmDialectConfig.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmDriver.d.ts +0 -13
- package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmDriver.js +0 -57
- package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmDriver.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/kysely/index.d.ts +0 -4
- package/node_modules/sqlite-wasm-kysely/dist/kysely/index.js +0 -4
- package/node_modules/sqlite-wasm-kysely/dist/kysely/index.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/kysely/sqliteModule.d.ts +0 -3
- package/node_modules/sqlite-wasm-kysely/dist/kysely/sqliteModule.js +0 -5
- package/node_modules/sqlite-wasm-kysely/dist/kysely/sqliteModule.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/util/contentFromDatabase.d.ts +0 -9
- package/node_modules/sqlite-wasm-kysely/dist/util/contentFromDatabase.js +0 -12
- package/node_modules/sqlite-wasm-kysely/dist/util/contentFromDatabase.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/util/createInMemoryDatabase.d.ts +0 -3
- package/node_modules/sqlite-wasm-kysely/dist/util/createInMemoryDatabase.js +0 -22
- package/node_modules/sqlite-wasm-kysely/dist/util/createInMemoryDatabase.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/util/importDatabase.d.ts +0 -7
- package/node_modules/sqlite-wasm-kysely/dist/util/importDatabase.js +0 -15
- package/node_modules/sqlite-wasm-kysely/dist/util/importDatabase.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/util/index.d.ts +0 -5
- package/node_modules/sqlite-wasm-kysely/dist/util/index.js +0 -5
- package/node_modules/sqlite-wasm-kysely/dist/util/index.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/util/loadDatabaseInMemory.d.ts +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/util/loadDatabaseInMemory.js +0 -13
- package/node_modules/sqlite-wasm-kysely/dist/util/loadDatabaseInMemory.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/dist/util/sqliteWasmBinary.d.ts +0 -7
- package/node_modules/sqlite-wasm-kysely/dist/util/sqliteWasmBinary.js +0 -17
- package/node_modules/sqlite-wasm-kysely/dist/util/sqliteWasmBinary.js.map +0 -1
- package/node_modules/sqlite-wasm-kysely/package.json +0 -34
- package/node_modules/sqlite-wasm-kysely/src/dialect.ts +0 -15
- package/node_modules/sqlite-wasm-kysely/src/index.ts +0 -2
- package/node_modules/sqlite-wasm-kysely/src/kysely/ConnectionMutex.ts +0 -23
- package/node_modules/sqlite-wasm-kysely/src/kysely/SqliteWasmConnection.ts +0 -57
- package/node_modules/sqlite-wasm-kysely/src/kysely/SqliteWasmDialectConfig.ts +0 -19
- package/node_modules/sqlite-wasm-kysely/src/kysely/SqliteWasmDriver.ts +0 -58
- package/node_modules/sqlite-wasm-kysely/src/kysely/index.ts +0 -4
- package/node_modules/sqlite-wasm-kysely/src/kysely/sqliteModule.ts +0 -7
- package/node_modules/sqlite-wasm-kysely/src/util/contentFromDatabase.ts +0 -13
- package/node_modules/sqlite-wasm-kysely/src/util/createInMemoryDatabase.ts +0 -30
- package/node_modules/sqlite-wasm-kysely/src/util/importDatabase.ts +0 -34
- package/node_modules/sqlite-wasm-kysely/src/util/index.ts +0 -5
- package/node_modules/sqlite-wasm-kysely/src/util/loadDatabaseInMemory.ts +0 -13
- package/node_modules/sqlite-wasm-kysely/src/util/sqliteWasmBinary.ts +0 -20
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sqliteWasmBinary.js","sourceRoot":"","sources":["../../src/util/sqliteWasmBinary.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,SAAS,mBAAmB,CAAC,MAAc;IACzC,IAAI,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAChC,IAAI,KAAK,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAChD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7C,KAAK,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,CAAC;AACtB,CAAC;AAED,MAAM,gBAAgB,GACpB,sgtsCAAsgtsC,CAAC;AAEzgtsC,MAAM,CAAC,MAAM,UAAU,GAAG,mBAAmB,CAAC,gBAAgB,CAAC,CAAC"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"private": true,
|
|
3
|
-
"name": "sqlite-wasm-kysely",
|
|
4
|
-
"version": "0.1.0",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"exports": {
|
|
7
|
-
".": "./dist/index.js"
|
|
8
|
-
},
|
|
9
|
-
"files": [
|
|
10
|
-
"dist",
|
|
11
|
-
"src"
|
|
12
|
-
],
|
|
13
|
-
"scripts": {
|
|
14
|
-
"build": "tsc",
|
|
15
|
-
"test": "tsc --noEmit && vitest run",
|
|
16
|
-
"test:watch": "vitest",
|
|
17
|
-
"format": "prettier . --write"
|
|
18
|
-
},
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"@eliaspourquoi/sqlite-node-wasm": "^3.46.0-build2"
|
|
21
|
-
},
|
|
22
|
-
"devDependencies": {
|
|
23
|
-
"@vitest/browser": "^1.6.0",
|
|
24
|
-
"kysely": "^0.27.4",
|
|
25
|
-
"prettier": "^3.3.2",
|
|
26
|
-
"typescript": "^5.5.3",
|
|
27
|
-
"vite": "^5.3.3",
|
|
28
|
-
"vitest": "^1.6.0",
|
|
29
|
-
"webdriverio": "^8.39.1"
|
|
30
|
-
},
|
|
31
|
-
"peerDependencies": {
|
|
32
|
-
"kysely": "*"
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { SqliteAdapter, SqliteIntrospector, SqliteQueryCompiler } from "kysely";
|
|
2
|
-
import { SqliteWasmDriver } from "./kysely/SqliteWasmDriver.js";
|
|
3
|
-
import { Database } from "@eliaspourquoi/sqlite-node-wasm";
|
|
4
|
-
|
|
5
|
-
export const createDialect = (args: { database: Database }) => {
|
|
6
|
-
return {
|
|
7
|
-
createAdapter: () => new SqliteAdapter(),
|
|
8
|
-
createDriver: () =>
|
|
9
|
-
new SqliteWasmDriver({
|
|
10
|
-
database: args.database,
|
|
11
|
-
}),
|
|
12
|
-
createIntrospector: (db: any) => new SqliteIntrospector(db),
|
|
13
|
-
createQueryCompiler: () => new SqliteQueryCompiler(),
|
|
14
|
-
};
|
|
15
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export class ConnectionMutex {
|
|
2
|
-
#promise?: Promise<void>;
|
|
3
|
-
#resolve?: () => void;
|
|
4
|
-
|
|
5
|
-
async lock(): Promise<void> {
|
|
6
|
-
while (this.#promise) {
|
|
7
|
-
await this.#promise;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
this.#promise = new Promise((resolve) => {
|
|
11
|
-
this.#resolve = resolve;
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
unlock(): void {
|
|
16
|
-
const resolve = this.#resolve;
|
|
17
|
-
|
|
18
|
-
this.#promise = undefined;
|
|
19
|
-
this.#resolve = undefined;
|
|
20
|
-
|
|
21
|
-
resolve?.();
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { CompiledQuery, DatabaseConnection, QueryResult } from "kysely";
|
|
2
|
-
import { Database } from "@eliaspourquoi/sqlite-node-wasm";
|
|
3
|
-
import { sqliteModule } from "./sqliteModule.js";
|
|
4
|
-
|
|
5
|
-
export class SqliteWasmConnection implements DatabaseConnection {
|
|
6
|
-
readonly #db: Database;
|
|
7
|
-
|
|
8
|
-
constructor(db: Database) {
|
|
9
|
-
this.#db = db;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
executeQuery<O>(compiledQuery: CompiledQuery): Promise<QueryResult<O>> {
|
|
13
|
-
const { sql, parameters } = compiledQuery;
|
|
14
|
-
|
|
15
|
-
const statementData = {
|
|
16
|
-
rows: [],
|
|
17
|
-
columns: [],
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
// we cant know what kind of query we are dealing with at that state - unless we switch to perpared statments
|
|
21
|
-
// for now we collect all information required
|
|
22
|
-
// save the changes before (total changes seems to be fast and worth the twoe extra round trips inspiration from https://github.com/WiseLibs/better-sqlite3/blob/254b8e93d78b1b03c9a2c777f4d304a0ea1530c6/src/objects/statement.lzz#L159)
|
|
23
|
-
const totalChangesBefore = this.#db.changes(true);
|
|
24
|
-
|
|
25
|
-
// execute the statement
|
|
26
|
-
const rows = this.#db.exec({
|
|
27
|
-
sql: sql,
|
|
28
|
-
bind: parameters as any,
|
|
29
|
-
returnValue: "resultRows",
|
|
30
|
-
rowMode: "object",
|
|
31
|
-
columnNames: statementData.columns,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const lastInsertId = sqliteModule?.capi.sqlite3_last_insert_rowid(this.#db);
|
|
35
|
-
|
|
36
|
-
// check if we had changes in the db at all - if so - collect the number of changes
|
|
37
|
-
const changes =
|
|
38
|
-
totalChangesBefore === this.#db.changes(true) ? 0 : this.#db.changes();
|
|
39
|
-
|
|
40
|
-
// console.log('sql: ' + sql);
|
|
41
|
-
// console.log('result: ', rows);
|
|
42
|
-
// We don't have knowledge about rather its update/delete/or select - so we return the results
|
|
43
|
-
// @ts-expect-error - TODO for @martin-lysk - typescript complains
|
|
44
|
-
return Promise.resolve({
|
|
45
|
-
numAffectedRows: changes,
|
|
46
|
-
insertId: lastInsertId,
|
|
47
|
-
|
|
48
|
-
// queries with result
|
|
49
|
-
rows: rows as O[],
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// eslint-disable-next-line require-yield
|
|
54
|
-
async *streamQuery() {
|
|
55
|
-
throw new Error("not supported for wasm driver yet");
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { DatabaseConnection } from "kysely";
|
|
2
|
-
import { Database } from "@eliaspourquoi/sqlite-node-wasm";
|
|
3
|
-
|
|
4
|
-
export interface SqliteWasmDialectConfig {
|
|
5
|
-
/**
|
|
6
|
-
* An sqlite Database instance or a function that returns one.
|
|
7
|
-
*
|
|
8
|
-
* If a function is provided, it's called once when the first query is executed.
|
|
9
|
-
*
|
|
10
|
-
* https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/api.md#new-databasepath-options
|
|
11
|
-
*/
|
|
12
|
-
database: Database | (() => Promise<Database>);
|
|
13
|
-
/**
|
|
14
|
-
* Called once when the first query is executed.
|
|
15
|
-
*
|
|
16
|
-
* This is a Kysely specific feature and does not come from the `better-sqlite3` module.
|
|
17
|
-
*/
|
|
18
|
-
onCreateConnection?: (connection: DatabaseConnection) => Promise<void>;
|
|
19
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { CompiledQuery, DatabaseConnection, Driver } from "kysely";
|
|
2
|
-
import { Database } from "@eliaspourquoi/sqlite-node-wasm";
|
|
3
|
-
import { SqliteWasmDialectConfig } from "./SqliteWasmDialectConfig.js";
|
|
4
|
-
import { ConnectionMutex } from "./ConnectionMutex.js";
|
|
5
|
-
import { SqliteWasmConnection } from "./SqliteWasmConnection.js";
|
|
6
|
-
|
|
7
|
-
export class SqliteWasmDriver implements Driver {
|
|
8
|
-
readonly #config: SqliteWasmDialectConfig;
|
|
9
|
-
readonly #connectionMutex = new ConnectionMutex();
|
|
10
|
-
|
|
11
|
-
#db?: Database;
|
|
12
|
-
#connection?: DatabaseConnection;
|
|
13
|
-
|
|
14
|
-
constructor(config: SqliteWasmDialectConfig) {
|
|
15
|
-
// this.#config = freeze({ ...config })
|
|
16
|
-
this.#config = { ...config };
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async init(): Promise<void> {
|
|
20
|
-
this.#db =
|
|
21
|
-
typeof this.#config.database === "function"
|
|
22
|
-
? await this.#config.database()
|
|
23
|
-
: this.#config.database;
|
|
24
|
-
|
|
25
|
-
this.#connection = new SqliteWasmConnection(this.#db);
|
|
26
|
-
|
|
27
|
-
if (this.#config.onCreateConnection) {
|
|
28
|
-
await this.#config.onCreateConnection(this.#connection);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async acquireConnection(): Promise<DatabaseConnection> {
|
|
33
|
-
// SQLite only has one single connection. We use a mutex here to wait
|
|
34
|
-
// until the single connection has been released.
|
|
35
|
-
await this.#connectionMutex.lock();
|
|
36
|
-
return this.#connection!;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async beginTransaction(connection: DatabaseConnection): Promise<void> {
|
|
40
|
-
await connection.executeQuery(CompiledQuery.raw("begin"));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async commitTransaction(connection: DatabaseConnection): Promise<void> {
|
|
44
|
-
await connection.executeQuery(CompiledQuery.raw("commit"));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async rollbackTransaction(connection: DatabaseConnection): Promise<void> {
|
|
48
|
-
await connection.executeQuery(CompiledQuery.raw("rollback"));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async releaseConnection(): Promise<void> {
|
|
52
|
-
this.#connectionMutex.unlock();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async destroy(): Promise<void> {
|
|
56
|
-
this.#db?.close();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Database } from "@eliaspourquoi/sqlite-node-wasm";
|
|
2
|
-
import { sqliteModule } from "../kysely/sqliteModule.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Exports the content of a database as a Uint8Array.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* const db = createInMemoryDatabase({ readOnly: false });
|
|
9
|
-
* const content = contentFromDatabase(db);
|
|
10
|
-
*/
|
|
11
|
-
export const contentFromDatabase = (db: Database): Uint8Array => {
|
|
12
|
-
return sqliteModule.capi.sqlite3_js_db_export(db);
|
|
13
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import sqlite3InitModule from "@eliaspourquoi/sqlite-node-wasm";
|
|
2
|
-
import { setSqliteModule, sqliteModule } from "../kysely/sqliteModule.js";
|
|
3
|
-
import { wasmBinary } from "./sqliteWasmBinary.js";
|
|
4
|
-
|
|
5
|
-
export const createInMemoryDatabase = async ({
|
|
6
|
-
readOnly = false,
|
|
7
|
-
}: {
|
|
8
|
-
readOnly?: boolean;
|
|
9
|
-
}) => {
|
|
10
|
-
if (!sqliteModule) {
|
|
11
|
-
await initSqlite();
|
|
12
|
-
}
|
|
13
|
-
const flags = [
|
|
14
|
-
readOnly ? "r" : "cw", // read and write
|
|
15
|
-
"", // non verbose
|
|
16
|
-
].join("");
|
|
17
|
-
|
|
18
|
-
return new sqliteModule.oo1.DB(":memory:", flags);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
async function initSqlite() {
|
|
22
|
-
setSqliteModule(
|
|
23
|
-
await sqlite3InitModule({
|
|
24
|
-
// @ts-expect-error
|
|
25
|
-
wasmBinary: wasmBinary,
|
|
26
|
-
// https://github.com/opral/inlang-sdk/issues/170#issuecomment-2334768193
|
|
27
|
-
locateFile: () => "sqlite3.wasm",
|
|
28
|
-
}),
|
|
29
|
-
);
|
|
30
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { sqliteModule } from "../kysely/sqliteModule.js";
|
|
2
|
-
import { Database } from "@eliaspourquoi/sqlite-node-wasm";
|
|
3
|
-
|
|
4
|
-
export const importDatabase = ({
|
|
5
|
-
db,
|
|
6
|
-
content,
|
|
7
|
-
schema = "main",
|
|
8
|
-
readOnly = false,
|
|
9
|
-
}: {
|
|
10
|
-
db: Database;
|
|
11
|
-
content: Uint8Array;
|
|
12
|
-
schema?: string;
|
|
13
|
-
readOnly?: boolean;
|
|
14
|
-
}) => {
|
|
15
|
-
const deserializeFlag = readOnly
|
|
16
|
-
? sqliteModule.capi.SQLITE_DESERIALIZE_READONLY
|
|
17
|
-
: sqliteModule.capi.SQLITE_DESERIALIZE_FREEONCLOSE |
|
|
18
|
-
sqliteModule.capi.SQLITE_DESERIALIZE_RESIZEABLE;
|
|
19
|
-
|
|
20
|
-
const contentPointer = sqliteModule.wasm.allocFromTypedArray(content);
|
|
21
|
-
const deserializeReturnCode = sqliteModule.capi.sqlite3_deserialize(
|
|
22
|
-
db.pointer!,
|
|
23
|
-
schema,
|
|
24
|
-
contentPointer,
|
|
25
|
-
content.byteLength, // db size
|
|
26
|
-
content.byteLength, // content size
|
|
27
|
-
deserializeFlag,
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
// check if the deserialization was successfull
|
|
31
|
-
db.checkRc(deserializeReturnCode);
|
|
32
|
-
|
|
33
|
-
return db;
|
|
34
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { contentFromDatabase } from "./contentFromDatabase.js";
|
|
2
|
-
export { createInMemoryDatabase } from "./createInMemoryDatabase.js";
|
|
3
|
-
export { importDatabase } from "./importDatabase.js";
|
|
4
|
-
export type { Database as SqliteDatabase } from "@eliaspourquoi/sqlite-node-wasm";
|
|
5
|
-
export { loadDatabaseInMemory } from "./loadDatabaseInMemory.js";
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { createInMemoryDatabase } from "./createInMemoryDatabase.js";
|
|
2
|
-
import { importDatabase } from "./importDatabase.js";
|
|
3
|
-
|
|
4
|
-
export async function loadDatabaseInMemory(data: ArrayBuffer) {
|
|
5
|
-
const database = await createInMemoryDatabase({
|
|
6
|
-
readOnly: false,
|
|
7
|
-
});
|
|
8
|
-
importDatabase({
|
|
9
|
-
db: database,
|
|
10
|
-
content: new Uint8Array(data),
|
|
11
|
-
});
|
|
12
|
-
return database;
|
|
13
|
-
}
|