@zenstackhq/kysely-sql-js 3.0.0-alpha.17
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/LICENSE +21 -0
- package/README.md +25 -0
- package/dist/index.cjs +110 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +39 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +83 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 ZenStack
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Forked from https://github.com/betarixm/kysely-sql-js
|
|
2
|
+
|
|
3
|
+
## Usage
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { type GeneratedAlways, Kysely } from 'kysely';
|
|
7
|
+
import initSqlJs from 'sql.js';
|
|
8
|
+
|
|
9
|
+
import { SqlJsDialect } from '@zenstackhq/kysely-sql-js';
|
|
10
|
+
|
|
11
|
+
interface Database {
|
|
12
|
+
person: {
|
|
13
|
+
id: GeneratedAlways<number>;
|
|
14
|
+
first_name: string | null;
|
|
15
|
+
last_name: string | null;
|
|
16
|
+
age: number;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const SqlJsStatic = await initSqlJs();
|
|
21
|
+
|
|
22
|
+
export const db = new Kysely<Database>({
|
|
23
|
+
dialect: new SqlJsDialect({ sqlJs: new SqlJsStatic.Database() }),
|
|
24
|
+
});
|
|
25
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var src_exports = {};
|
|
23
|
+
__export(src_exports, {
|
|
24
|
+
SqlJsConnection: () => SqlJsConnection,
|
|
25
|
+
SqlJsDialect: () => SqlJsDialect,
|
|
26
|
+
SqlJsDriver: () => SqlJsDriver
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(src_exports);
|
|
29
|
+
|
|
30
|
+
// src/connection.ts
|
|
31
|
+
var SqlJsConnection = class {
|
|
32
|
+
static {
|
|
33
|
+
__name(this, "SqlJsConnection");
|
|
34
|
+
}
|
|
35
|
+
database;
|
|
36
|
+
constructor(database) {
|
|
37
|
+
this.database = database;
|
|
38
|
+
}
|
|
39
|
+
async executeQuery(compiledQuery) {
|
|
40
|
+
const executeResult = this.database.exec(compiledQuery.sql, compiledQuery.parameters);
|
|
41
|
+
const rowsModified = this.database.getRowsModified();
|
|
42
|
+
return {
|
|
43
|
+
numAffectedRows: BigInt(rowsModified),
|
|
44
|
+
rows: executeResult.map(({ columns, values }) => values.map((row) => columns.reduce((acc, column, i) => ({
|
|
45
|
+
...acc,
|
|
46
|
+
[column]: row[i]
|
|
47
|
+
}), {}))).flat()
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// eslint-disable-next-line require-yield
|
|
51
|
+
async *streamQuery() {
|
|
52
|
+
throw new Error("Not supported with SQLite");
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// src/dialect.ts
|
|
57
|
+
var import_kysely2 = require("kysely");
|
|
58
|
+
|
|
59
|
+
// src/driver.ts
|
|
60
|
+
var import_kysely = require("kysely");
|
|
61
|
+
var SqlJsDriver = class {
|
|
62
|
+
static {
|
|
63
|
+
__name(this, "SqlJsDriver");
|
|
64
|
+
}
|
|
65
|
+
config;
|
|
66
|
+
constructor(config) {
|
|
67
|
+
this.config = config;
|
|
68
|
+
}
|
|
69
|
+
async acquireConnection() {
|
|
70
|
+
return new SqlJsConnection(this.config.sqlJs);
|
|
71
|
+
}
|
|
72
|
+
async beginTransaction(connection) {
|
|
73
|
+
await connection.executeQuery(import_kysely.CompiledQuery.raw("BEGIN"));
|
|
74
|
+
}
|
|
75
|
+
async commitTransaction(connection) {
|
|
76
|
+
await connection.executeQuery(import_kysely.CompiledQuery.raw("COMMIT"));
|
|
77
|
+
}
|
|
78
|
+
async rollbackTransaction(connection) {
|
|
79
|
+
await connection.executeQuery(import_kysely.CompiledQuery.raw("ROLLBACK"));
|
|
80
|
+
}
|
|
81
|
+
async destroy() {
|
|
82
|
+
this.config.sqlJs.close();
|
|
83
|
+
}
|
|
84
|
+
async init() {
|
|
85
|
+
}
|
|
86
|
+
async releaseConnection(_connection) {
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// src/dialect.ts
|
|
91
|
+
var SqlJsDialect = class {
|
|
92
|
+
static {
|
|
93
|
+
__name(this, "SqlJsDialect");
|
|
94
|
+
}
|
|
95
|
+
config;
|
|
96
|
+
constructor(config) {
|
|
97
|
+
this.config = config;
|
|
98
|
+
}
|
|
99
|
+
createAdapter = /* @__PURE__ */ __name(() => new import_kysely2.SqliteAdapter(), "createAdapter");
|
|
100
|
+
createDriver = /* @__PURE__ */ __name(() => new SqlJsDriver(this.config), "createDriver");
|
|
101
|
+
createIntrospector = /* @__PURE__ */ __name((db) => new import_kysely2.SqliteIntrospector(db), "createIntrospector");
|
|
102
|
+
createQueryCompiler = /* @__PURE__ */ __name(() => new import_kysely2.SqliteQueryCompiler(), "createQueryCompiler");
|
|
103
|
+
};
|
|
104
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
+
0 && (module.exports = {
|
|
106
|
+
SqlJsConnection,
|
|
107
|
+
SqlJsDialect,
|
|
108
|
+
SqlJsDriver
|
|
109
|
+
});
|
|
110
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/connection.ts","../src/dialect.ts","../src/driver.ts"],"sourcesContent":["export * from './connection';\nexport * from './dialect';\nexport * from './driver';\nexport * from './types';\n","import type { DatabaseConnection, QueryResult } from 'kysely';\nimport type { BindParams, Database } from 'sql.js';\n\nimport { CompiledQuery } from 'kysely';\n\nexport class SqlJsConnection implements DatabaseConnection {\n private database: Database;\n\n constructor(database: Database) {\n this.database = database;\n }\n\n async executeQuery<R>(compiledQuery: CompiledQuery<unknown>): Promise<QueryResult<R>> {\n const executeResult = this.database.exec(compiledQuery.sql, compiledQuery.parameters as BindParams);\n const rowsModified = this.database.getRowsModified();\n return {\n numAffectedRows: BigInt(rowsModified),\n rows: executeResult\n .map(({ columns, values }) =>\n values.map((row) => columns.reduce((acc, column, i) => ({ ...acc, [column]: row[i] }), {}) as R),\n )\n .flat(),\n };\n }\n\n // eslint-disable-next-line require-yield\n async *streamQuery() {\n throw new Error('Not supported with SQLite');\n }\n}\n","import type { Dialect } from 'kysely';\n\nimport type { SqlJsDialectConfig } from './types';\n\nimport { Kysely, SqliteAdapter, SqliteIntrospector, SqliteQueryCompiler } from 'kysely';\n\nimport { SqlJsDriver } from './driver';\n\n/**\n * The SqlJsDialect is for testing purposes only and should not be used in production.\n */\nexport class SqlJsDialect implements Dialect {\n private config: SqlJsDialectConfig;\n\n constructor(config: SqlJsDialectConfig) {\n this.config = config;\n }\n\n createAdapter = () => new SqliteAdapter();\n\n createDriver = () => new SqlJsDriver(this.config);\n\n createIntrospector = (db: Kysely<any>) => new SqliteIntrospector(db);\n\n createQueryCompiler = () => new SqliteQueryCompiler();\n}\n","import type { DatabaseConnection, Driver } from 'kysely';\n\nimport { CompiledQuery } from 'kysely';\n\nimport { SqlJsConnection } from './connection';\nimport type { SqlJsDialectConfig } from './types';\n\nexport class SqlJsDriver implements Driver {\n private config: SqlJsDialectConfig;\n\n constructor(config: SqlJsDialectConfig) {\n this.config = config;\n }\n\n async acquireConnection(): Promise<DatabaseConnection> {\n return new SqlJsConnection(this.config.sqlJs);\n }\n\n async beginTransaction(connection: DatabaseConnection): Promise<void> {\n await connection.executeQuery(CompiledQuery.raw('BEGIN'));\n }\n\n async commitTransaction(connection: DatabaseConnection): Promise<void> {\n await connection.executeQuery(CompiledQuery.raw('COMMIT'));\n }\n\n async rollbackTransaction(connection: DatabaseConnection): Promise<void> {\n await connection.executeQuery(CompiledQuery.raw('ROLLBACK'));\n }\n\n async destroy(): Promise<void> {\n this.config.sqlJs.close();\n }\n\n async init() {}\n\n async releaseConnection(_connection: DatabaseConnection): Promise<void> {}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACKO,IAAMA,kBAAN,MAAMA;EAAb,OAAaA;;;EACDC;EAER,YAAYA,UAAoB;AAC5B,SAAKA,WAAWA;EACpB;EAEA,MAAMC,aAAgBC,eAAgE;AAClF,UAAMC,gBAAgB,KAAKH,SAASI,KAAKF,cAAcG,KAAKH,cAAcI,UAAU;AACpF,UAAMC,eAAe,KAAKP,SAASQ,gBAAe;AAClD,WAAO;MACHC,iBAAiBC,OAAOH,YAAAA;MACxBI,MAAMR,cACDS,IAAI,CAAC,EAAEC,SAASC,OAAM,MACnBA,OAAOF,IAAI,CAACG,QAAQF,QAAQG,OAAO,CAACC,KAAKC,QAAQC,OAAO;QAAE,GAAGF;QAAK,CAACC,MAAAA,GAASH,IAAII,CAAAA;MAAG,IAAI,CAAC,CAAA,CAAA,CAAA,EAE3FC,KAAI;IACb;EACJ;;EAGA,OAAOC,cAAc;AACjB,UAAM,IAAIC,MAAM,2BAAA;EACpB;AACJ;;;ACzBA,IAAAC,iBAA+E;;;ACF/E,oBAA8B;AAKvB,IAAMC,cAAN,MAAMA;EALb,OAKaA;;;EACDC;EAER,YAAYA,QAA4B;AACpC,SAAKA,SAASA;EAClB;EAEA,MAAMC,oBAAiD;AACnD,WAAO,IAAIC,gBAAgB,KAAKF,OAAOG,KAAK;EAChD;EAEA,MAAMC,iBAAiBC,YAA+C;AAClE,UAAMA,WAAWC,aAAaC,4BAAcC,IAAI,OAAA,CAAA;EACpD;EAEA,MAAMC,kBAAkBJ,YAA+C;AACnE,UAAMA,WAAWC,aAAaC,4BAAcC,IAAI,QAAA,CAAA;EACpD;EAEA,MAAME,oBAAoBL,YAA+C;AACrE,UAAMA,WAAWC,aAAaC,4BAAcC,IAAI,UAAA,CAAA;EACpD;EAEA,MAAMG,UAAyB;AAC3B,SAAKX,OAAOG,MAAMS,MAAK;EAC3B;EAEA,MAAMC,OAAO;EAAC;EAEd,MAAMC,kBAAkBC,aAAgD;EAAC;AAC7E;;;AD1BO,IAAMC,eAAN,MAAMA;EAPb,OAOaA;;;EACDC;EAER,YAAYA,QAA4B;AACpC,SAAKA,SAASA;EAClB;EAEAC,gBAAgB,6BAAM,IAAIC,6BAAAA,GAAV;EAEhBC,eAAe,6BAAM,IAAIC,YAAY,KAAKJ,MAAM,GAAjC;EAEfK,qBAAqB,wBAACC,OAAoB,IAAIC,kCAAmBD,EAAAA,GAA5C;EAErBE,sBAAsB,6BAAM,IAAIC,mCAAAA,GAAV;AAC1B;","names":["SqlJsConnection","database","executeQuery","compiledQuery","executeResult","exec","sql","parameters","rowsModified","getRowsModified","numAffectedRows","BigInt","rows","map","columns","values","row","reduce","acc","column","i","flat","streamQuery","Error","import_kysely","SqlJsDriver","config","acquireConnection","SqlJsConnection","sqlJs","beginTransaction","connection","executeQuery","CompiledQuery","raw","commitTransaction","rollbackTransaction","destroy","close","init","releaseConnection","_connection","SqlJsDialect","config","createAdapter","SqliteAdapter","createDriver","SqlJsDriver","createIntrospector","db","SqliteIntrospector","createQueryCompiler","SqliteQueryCompiler"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { DatabaseConnection, CompiledQuery, QueryResult, Driver, Dialect, SqliteAdapter, Kysely, SqliteIntrospector, SqliteQueryCompiler } from 'kysely';
|
|
2
|
+
import { Database } from 'sql.js';
|
|
3
|
+
|
|
4
|
+
declare class SqlJsConnection implements DatabaseConnection {
|
|
5
|
+
private database;
|
|
6
|
+
constructor(database: Database);
|
|
7
|
+
executeQuery<R>(compiledQuery: CompiledQuery<unknown>): Promise<QueryResult<R>>;
|
|
8
|
+
streamQuery(): AsyncGenerator<never, void, unknown>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface SqlJsDialectConfig {
|
|
12
|
+
sqlJs: Database;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare class SqlJsDriver implements Driver {
|
|
16
|
+
private config;
|
|
17
|
+
constructor(config: SqlJsDialectConfig);
|
|
18
|
+
acquireConnection(): Promise<DatabaseConnection>;
|
|
19
|
+
beginTransaction(connection: DatabaseConnection): Promise<void>;
|
|
20
|
+
commitTransaction(connection: DatabaseConnection): Promise<void>;
|
|
21
|
+
rollbackTransaction(connection: DatabaseConnection): Promise<void>;
|
|
22
|
+
destroy(): Promise<void>;
|
|
23
|
+
init(): Promise<void>;
|
|
24
|
+
releaseConnection(_connection: DatabaseConnection): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The SqlJsDialect is for testing purposes only and should not be used in production.
|
|
29
|
+
*/
|
|
30
|
+
declare class SqlJsDialect implements Dialect {
|
|
31
|
+
private config;
|
|
32
|
+
constructor(config: SqlJsDialectConfig);
|
|
33
|
+
createAdapter: () => SqliteAdapter;
|
|
34
|
+
createDriver: () => SqlJsDriver;
|
|
35
|
+
createIntrospector: (db: Kysely<any>) => SqliteIntrospector;
|
|
36
|
+
createQueryCompiler: () => SqliteQueryCompiler;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { SqlJsConnection, SqlJsDialect, type SqlJsDialectConfig, SqlJsDriver };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { DatabaseConnection, CompiledQuery, QueryResult, Driver, Dialect, SqliteAdapter, Kysely, SqliteIntrospector, SqliteQueryCompiler } from 'kysely';
|
|
2
|
+
import { Database } from 'sql.js';
|
|
3
|
+
|
|
4
|
+
declare class SqlJsConnection implements DatabaseConnection {
|
|
5
|
+
private database;
|
|
6
|
+
constructor(database: Database);
|
|
7
|
+
executeQuery<R>(compiledQuery: CompiledQuery<unknown>): Promise<QueryResult<R>>;
|
|
8
|
+
streamQuery(): AsyncGenerator<never, void, unknown>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface SqlJsDialectConfig {
|
|
12
|
+
sqlJs: Database;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare class SqlJsDriver implements Driver {
|
|
16
|
+
private config;
|
|
17
|
+
constructor(config: SqlJsDialectConfig);
|
|
18
|
+
acquireConnection(): Promise<DatabaseConnection>;
|
|
19
|
+
beginTransaction(connection: DatabaseConnection): Promise<void>;
|
|
20
|
+
commitTransaction(connection: DatabaseConnection): Promise<void>;
|
|
21
|
+
rollbackTransaction(connection: DatabaseConnection): Promise<void>;
|
|
22
|
+
destroy(): Promise<void>;
|
|
23
|
+
init(): Promise<void>;
|
|
24
|
+
releaseConnection(_connection: DatabaseConnection): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The SqlJsDialect is for testing purposes only and should not be used in production.
|
|
29
|
+
*/
|
|
30
|
+
declare class SqlJsDialect implements Dialect {
|
|
31
|
+
private config;
|
|
32
|
+
constructor(config: SqlJsDialectConfig);
|
|
33
|
+
createAdapter: () => SqliteAdapter;
|
|
34
|
+
createDriver: () => SqlJsDriver;
|
|
35
|
+
createIntrospector: (db: Kysely<any>) => SqliteIntrospector;
|
|
36
|
+
createQueryCompiler: () => SqliteQueryCompiler;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { SqlJsConnection, SqlJsDialect, type SqlJsDialectConfig, SqlJsDriver };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/connection.ts
|
|
5
|
+
var SqlJsConnection = class {
|
|
6
|
+
static {
|
|
7
|
+
__name(this, "SqlJsConnection");
|
|
8
|
+
}
|
|
9
|
+
database;
|
|
10
|
+
constructor(database) {
|
|
11
|
+
this.database = database;
|
|
12
|
+
}
|
|
13
|
+
async executeQuery(compiledQuery) {
|
|
14
|
+
const executeResult = this.database.exec(compiledQuery.sql, compiledQuery.parameters);
|
|
15
|
+
const rowsModified = this.database.getRowsModified();
|
|
16
|
+
return {
|
|
17
|
+
numAffectedRows: BigInt(rowsModified),
|
|
18
|
+
rows: executeResult.map(({ columns, values }) => values.map((row) => columns.reduce((acc, column, i) => ({
|
|
19
|
+
...acc,
|
|
20
|
+
[column]: row[i]
|
|
21
|
+
}), {}))).flat()
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
// eslint-disable-next-line require-yield
|
|
25
|
+
async *streamQuery() {
|
|
26
|
+
throw new Error("Not supported with SQLite");
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// src/dialect.ts
|
|
31
|
+
import { SqliteAdapter, SqliteIntrospector, SqliteQueryCompiler } from "kysely";
|
|
32
|
+
|
|
33
|
+
// src/driver.ts
|
|
34
|
+
import { CompiledQuery } from "kysely";
|
|
35
|
+
var SqlJsDriver = class {
|
|
36
|
+
static {
|
|
37
|
+
__name(this, "SqlJsDriver");
|
|
38
|
+
}
|
|
39
|
+
config;
|
|
40
|
+
constructor(config) {
|
|
41
|
+
this.config = config;
|
|
42
|
+
}
|
|
43
|
+
async acquireConnection() {
|
|
44
|
+
return new SqlJsConnection(this.config.sqlJs);
|
|
45
|
+
}
|
|
46
|
+
async beginTransaction(connection) {
|
|
47
|
+
await connection.executeQuery(CompiledQuery.raw("BEGIN"));
|
|
48
|
+
}
|
|
49
|
+
async commitTransaction(connection) {
|
|
50
|
+
await connection.executeQuery(CompiledQuery.raw("COMMIT"));
|
|
51
|
+
}
|
|
52
|
+
async rollbackTransaction(connection) {
|
|
53
|
+
await connection.executeQuery(CompiledQuery.raw("ROLLBACK"));
|
|
54
|
+
}
|
|
55
|
+
async destroy() {
|
|
56
|
+
this.config.sqlJs.close();
|
|
57
|
+
}
|
|
58
|
+
async init() {
|
|
59
|
+
}
|
|
60
|
+
async releaseConnection(_connection) {
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// src/dialect.ts
|
|
65
|
+
var SqlJsDialect = class {
|
|
66
|
+
static {
|
|
67
|
+
__name(this, "SqlJsDialect");
|
|
68
|
+
}
|
|
69
|
+
config;
|
|
70
|
+
constructor(config) {
|
|
71
|
+
this.config = config;
|
|
72
|
+
}
|
|
73
|
+
createAdapter = /* @__PURE__ */ __name(() => new SqliteAdapter(), "createAdapter");
|
|
74
|
+
createDriver = /* @__PURE__ */ __name(() => new SqlJsDriver(this.config), "createDriver");
|
|
75
|
+
createIntrospector = /* @__PURE__ */ __name((db) => new SqliteIntrospector(db), "createIntrospector");
|
|
76
|
+
createQueryCompiler = /* @__PURE__ */ __name(() => new SqliteQueryCompiler(), "createQueryCompiler");
|
|
77
|
+
};
|
|
78
|
+
export {
|
|
79
|
+
SqlJsConnection,
|
|
80
|
+
SqlJsDialect,
|
|
81
|
+
SqlJsDriver
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/connection.ts","../src/dialect.ts","../src/driver.ts"],"sourcesContent":["import type { DatabaseConnection, QueryResult } from 'kysely';\nimport type { BindParams, Database } from 'sql.js';\n\nimport { CompiledQuery } from 'kysely';\n\nexport class SqlJsConnection implements DatabaseConnection {\n private database: Database;\n\n constructor(database: Database) {\n this.database = database;\n }\n\n async executeQuery<R>(compiledQuery: CompiledQuery<unknown>): Promise<QueryResult<R>> {\n const executeResult = this.database.exec(compiledQuery.sql, compiledQuery.parameters as BindParams);\n const rowsModified = this.database.getRowsModified();\n return {\n numAffectedRows: BigInt(rowsModified),\n rows: executeResult\n .map(({ columns, values }) =>\n values.map((row) => columns.reduce((acc, column, i) => ({ ...acc, [column]: row[i] }), {}) as R),\n )\n .flat(),\n };\n }\n\n // eslint-disable-next-line require-yield\n async *streamQuery() {\n throw new Error('Not supported with SQLite');\n }\n}\n","import type { Dialect } from 'kysely';\n\nimport type { SqlJsDialectConfig } from './types';\n\nimport { Kysely, SqliteAdapter, SqliteIntrospector, SqliteQueryCompiler } from 'kysely';\n\nimport { SqlJsDriver } from './driver';\n\n/**\n * The SqlJsDialect is for testing purposes only and should not be used in production.\n */\nexport class SqlJsDialect implements Dialect {\n private config: SqlJsDialectConfig;\n\n constructor(config: SqlJsDialectConfig) {\n this.config = config;\n }\n\n createAdapter = () => new SqliteAdapter();\n\n createDriver = () => new SqlJsDriver(this.config);\n\n createIntrospector = (db: Kysely<any>) => new SqliteIntrospector(db);\n\n createQueryCompiler = () => new SqliteQueryCompiler();\n}\n","import type { DatabaseConnection, Driver } from 'kysely';\n\nimport { CompiledQuery } from 'kysely';\n\nimport { SqlJsConnection } from './connection';\nimport type { SqlJsDialectConfig } from './types';\n\nexport class SqlJsDriver implements Driver {\n private config: SqlJsDialectConfig;\n\n constructor(config: SqlJsDialectConfig) {\n this.config = config;\n }\n\n async acquireConnection(): Promise<DatabaseConnection> {\n return new SqlJsConnection(this.config.sqlJs);\n }\n\n async beginTransaction(connection: DatabaseConnection): Promise<void> {\n await connection.executeQuery(CompiledQuery.raw('BEGIN'));\n }\n\n async commitTransaction(connection: DatabaseConnection): Promise<void> {\n await connection.executeQuery(CompiledQuery.raw('COMMIT'));\n }\n\n async rollbackTransaction(connection: DatabaseConnection): Promise<void> {\n await connection.executeQuery(CompiledQuery.raw('ROLLBACK'));\n }\n\n async destroy(): Promise<void> {\n this.config.sqlJs.close();\n }\n\n async init() {}\n\n async releaseConnection(_connection: DatabaseConnection): Promise<void> {}\n}\n"],"mappings":";;;;AAKO,IAAMA,kBAAN,MAAMA;EAAb,OAAaA;;;EACDC;EAER,YAAYA,UAAoB;AAC5B,SAAKA,WAAWA;EACpB;EAEA,MAAMC,aAAgBC,eAAgE;AAClF,UAAMC,gBAAgB,KAAKH,SAASI,KAAKF,cAAcG,KAAKH,cAAcI,UAAU;AACpF,UAAMC,eAAe,KAAKP,SAASQ,gBAAe;AAClD,WAAO;MACHC,iBAAiBC,OAAOH,YAAAA;MACxBI,MAAMR,cACDS,IAAI,CAAC,EAAEC,SAASC,OAAM,MACnBA,OAAOF,IAAI,CAACG,QAAQF,QAAQG,OAAO,CAACC,KAAKC,QAAQC,OAAO;QAAE,GAAGF;QAAK,CAACC,MAAAA,GAASH,IAAII,CAAAA;MAAG,IAAI,CAAC,CAAA,CAAA,CAAA,EAE3FC,KAAI;IACb;EACJ;;EAGA,OAAOC,cAAc;AACjB,UAAM,IAAIC,MAAM,2BAAA;EACpB;AACJ;;;ACzBA,SAAiBC,eAAeC,oBAAoBC,2BAA2B;;;ACF/E,SAASC,qBAAqB;AAKvB,IAAMC,cAAN,MAAMA;EALb,OAKaA;;;EACDC;EAER,YAAYA,QAA4B;AACpC,SAAKA,SAASA;EAClB;EAEA,MAAMC,oBAAiD;AACnD,WAAO,IAAIC,gBAAgB,KAAKF,OAAOG,KAAK;EAChD;EAEA,MAAMC,iBAAiBC,YAA+C;AAClE,UAAMA,WAAWC,aAAaC,cAAcC,IAAI,OAAA,CAAA;EACpD;EAEA,MAAMC,kBAAkBJ,YAA+C;AACnE,UAAMA,WAAWC,aAAaC,cAAcC,IAAI,QAAA,CAAA;EACpD;EAEA,MAAME,oBAAoBL,YAA+C;AACrE,UAAMA,WAAWC,aAAaC,cAAcC,IAAI,UAAA,CAAA;EACpD;EAEA,MAAMG,UAAyB;AAC3B,SAAKX,OAAOG,MAAMS,MAAK;EAC3B;EAEA,MAAMC,OAAO;EAAC;EAEd,MAAMC,kBAAkBC,aAAgD;EAAC;AAC7E;;;AD1BO,IAAMC,eAAN,MAAMA;EAPb,OAOaA;;;EACDC;EAER,YAAYA,QAA4B;AACpC,SAAKA,SAASA;EAClB;EAEAC,gBAAgB,6BAAM,IAAIC,cAAAA,GAAV;EAEhBC,eAAe,6BAAM,IAAIC,YAAY,KAAKJ,MAAM,GAAjC;EAEfK,qBAAqB,wBAACC,OAAoB,IAAIC,mBAAmBD,EAAAA,GAA5C;EAErBE,sBAAsB,6BAAM,IAAIC,oBAAAA,GAAV;AAC1B;","names":["SqlJsConnection","database","executeQuery","compiledQuery","executeResult","exec","sql","parameters","rowsModified","getRowsModified","numAffectedRows","BigInt","rows","map","columns","values","row","reduce","acc","column","i","flat","streamQuery","Error","SqliteAdapter","SqliteIntrospector","SqliteQueryCompiler","CompiledQuery","SqlJsDriver","config","acquireConnection","SqlJsConnection","sqlJs","beginTransaction","connection","executeQuery","CompiledQuery","raw","commitTransaction","rollbackTransaction","destroy","close","init","releaseConnection","_connection","SqlJsDialect","config","createAdapter","SqliteAdapter","createDriver","SqlJsDriver","createIntrospector","db","SqliteIntrospector","createQueryCompiler","SqliteQueryCompiler"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zenstackhq/kysely-sql-js",
|
|
3
|
+
"version": "3.0.0-alpha.17",
|
|
4
|
+
"description": "Kysely dialect for sql.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"keywords": [],
|
|
7
|
+
"author": "ZenStack Team",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"require": {
|
|
19
|
+
"types": "./dist/index.d.cts",
|
|
20
|
+
"default": "./dist/index.cjs"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/sql.js": "^1.4.9",
|
|
26
|
+
"sql.js": "^1.13.0",
|
|
27
|
+
"kysely": "^0.27.6",
|
|
28
|
+
"@zenstackhq/eslint-config": "3.0.0-alpha.17",
|
|
29
|
+
"@zenstackhq/typescript-config": "3.0.0-alpha.17",
|
|
30
|
+
"@zenstackhq/vitest-config": "3.0.0-alpha.17"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"sql.js": "^1.13.0",
|
|
34
|
+
"kysely": "^0.27.6"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsup-node",
|
|
38
|
+
"watch": "tsup-node --watch",
|
|
39
|
+
"lint": "eslint src --ext ts",
|
|
40
|
+
"pack": "pnpm pack"
|
|
41
|
+
}
|
|
42
|
+
}
|