@telorun/sql-sqlite 0.2.2 → 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/connection-controller.d.ts +11 -2
- package/dist/connection-controller.js +23 -2
- package/dist/sqlite-driver-bun.d.ts +1 -1
- package/dist/sqlite-driver-interface.d.ts +14 -0
- package/dist/sqlite-driver-interface.js +1 -0
- package/dist/sqlite-driver-node.d.ts +1 -1
- package/package.json +3 -3
- package/src/connection-controller.ts +29 -3
- package/src/sqlite-driver-bun.ts +1 -1
- package/src/sqlite-driver-interface.ts +15 -0
- package/src/sqlite-driver-node.ts +1 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { ResourceContext } from "@telorun/sdk";
|
|
2
|
-
import {
|
|
2
|
+
import { SqlConnectionBase } from "@telorun/sql";
|
|
3
|
+
import { Kysely } from "kysely";
|
|
4
|
+
import type { SqliteDb } from "./sqlite-driver-interface.js";
|
|
3
5
|
interface SqliteConnectionManifest {
|
|
4
6
|
metadata: {
|
|
5
7
|
name: string;
|
|
@@ -8,6 +10,13 @@ interface SqliteConnectionManifest {
|
|
|
8
10
|
/** File path, or omitted / `:memory:` for an in-memory database. */
|
|
9
11
|
file?: string;
|
|
10
12
|
}
|
|
13
|
+
declare class SqliteConnection extends SqlConnectionBase {
|
|
14
|
+
private readonly sqlite;
|
|
15
|
+
constructor(db: Kysely<any>, sqlite: SqliteDb);
|
|
16
|
+
/** The driver's native multi-statement entry point — kysely binds one
|
|
17
|
+
* statement per call. */
|
|
18
|
+
executeScript(sql: string): Promise<void>;
|
|
19
|
+
}
|
|
11
20
|
export declare function register(): void;
|
|
12
|
-
export declare function create(resource: SqliteConnectionManifest, _ctx: ResourceContext): Promise<
|
|
21
|
+
export declare function create(resource: SqliteConnectionManifest, _ctx: ResourceContext): Promise<SqliteConnection>;
|
|
13
22
|
export {};
|
|
@@ -1,5 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { quoteAnsiIdentifier, SqlConnectionBase } from "@telorun/sql";
|
|
2
2
|
import { Kysely, SqliteAdapter, SqliteDialect } from "kysely";
|
|
3
|
+
const sqliteDialect = {
|
|
4
|
+
placeholderStyle: "qmark",
|
|
5
|
+
quoteIdentifier: quoteAnsiIdentifier,
|
|
6
|
+
// SQLite has no array type, so set membership expands to one placeholder per
|
|
7
|
+
// element.
|
|
8
|
+
renderIn(column, values, addParam) {
|
|
9
|
+
return `${column} IN (${values.map((value) => addParam(value)).join(", ")})`;
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
class SqliteConnection extends SqlConnectionBase {
|
|
13
|
+
sqlite;
|
|
14
|
+
constructor(db, sqlite) {
|
|
15
|
+
super(db, sqliteDialect);
|
|
16
|
+
this.sqlite = sqlite;
|
|
17
|
+
}
|
|
18
|
+
/** The driver's native multi-statement entry point — kysely binds one
|
|
19
|
+
* statement per call. */
|
|
20
|
+
async executeScript(sql) {
|
|
21
|
+
this.sqlite.exec(sql);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
3
24
|
// Kysely's stock SQLite adapter reports `supportsTransactionalDdl = false`, so
|
|
4
25
|
// its Migrator runs migrations without a transaction. SQLite does support
|
|
5
26
|
// transactional DDL, so we flip the flag — letting the Migrator wrap the whole
|
|
@@ -42,5 +63,5 @@ export async function create(resource, _ctx) {
|
|
|
42
63
|
const db = new Kysely({
|
|
43
64
|
dialect: new TransactionalSqliteDialect({ database: sqlite }),
|
|
44
65
|
});
|
|
45
|
-
return
|
|
66
|
+
return new SqliteConnection(db, sqlite);
|
|
46
67
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { SqliteDb } from "
|
|
1
|
+
import type { SqliteDb } from "./sqlite-driver-interface.js";
|
|
2
2
|
export declare function openDatabase(file: string): SqliteDb;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface SqliteStatement {
|
|
2
|
+
readonly reader: boolean;
|
|
3
|
+
all(params: ReadonlyArray<unknown>): unknown[];
|
|
4
|
+
run(params: ReadonlyArray<unknown>): {
|
|
5
|
+
changes: number | bigint;
|
|
6
|
+
lastInsertRowid: number | bigint;
|
|
7
|
+
};
|
|
8
|
+
iterate(params: ReadonlyArray<unknown>): IterableIterator<unknown>;
|
|
9
|
+
}
|
|
10
|
+
export interface SqliteDb {
|
|
11
|
+
prepare(sql: string): SqliteStatement;
|
|
12
|
+
exec(sql: string): void;
|
|
13
|
+
close(): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { SqliteDb } from "
|
|
1
|
+
import type { SqliteDb } from "./sqlite-driver-interface.js";
|
|
2
2
|
export declare function openDatabase(file: string): SqliteDb;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telorun/sql-sqlite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Telo SqlSqlite.Connection — SQLite backend for the Sql.Connection abstract (better-sqlite3 / bun:sqlite, transactional DDL).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"telo",
|
|
@@ -36,14 +36,14 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"better-sqlite3": "^12.8.0",
|
|
38
38
|
"kysely": "^0.28.15",
|
|
39
|
-
"@telorun/sql": "0.
|
|
39
|
+
"@telorun/sql": "0.10.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/better-sqlite3": "^7.0.0",
|
|
43
43
|
"@types/bun": "^1.3.10",
|
|
44
44
|
"@types/node": "^20.0.0",
|
|
45
45
|
"typescript": "^5.0.0",
|
|
46
|
-
"@telorun/sdk": "0.
|
|
46
|
+
"@telorun/sdk": "0.58.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"@telorun/sdk": "*"
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ResourceContext } from "@telorun/sdk";
|
|
2
|
-
import {
|
|
2
|
+
import { quoteAnsiIdentifier, SqlConnectionBase, type SqlDialect } from "@telorun/sql";
|
|
3
3
|
import { Kysely, SqliteAdapter, SqliteDialect } from "kysely";
|
|
4
|
+
import type { SqliteDb } from "./sqlite-driver-interface.js";
|
|
4
5
|
|
|
5
6
|
interface SqliteConnectionManifest {
|
|
6
7
|
metadata: { name: string; module: string };
|
|
@@ -8,6 +9,31 @@ interface SqliteConnectionManifest {
|
|
|
8
9
|
file?: string;
|
|
9
10
|
}
|
|
10
11
|
|
|
12
|
+
const sqliteDialect: SqlDialect = {
|
|
13
|
+
placeholderStyle: "qmark",
|
|
14
|
+
quoteIdentifier: quoteAnsiIdentifier,
|
|
15
|
+
// SQLite has no array type, so set membership expands to one placeholder per
|
|
16
|
+
// element.
|
|
17
|
+
renderIn(column, values, addParam) {
|
|
18
|
+
return `${column} IN (${values.map((value) => addParam(value)).join(", ")})`;
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
class SqliteConnection extends SqlConnectionBase {
|
|
23
|
+
constructor(
|
|
24
|
+
db: Kysely<any>,
|
|
25
|
+
private readonly sqlite: SqliteDb,
|
|
26
|
+
) {
|
|
27
|
+
super(db, sqliteDialect);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The driver's native multi-statement entry point — kysely binds one
|
|
31
|
+
* statement per call. */
|
|
32
|
+
override async executeScript(sql: string): Promise<void> {
|
|
33
|
+
this.sqlite.exec(sql);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
11
37
|
// Kysely's stock SQLite adapter reports `supportsTransactionalDdl = false`, so
|
|
12
38
|
// its Migrator runs migrations without a transaction. SQLite does support
|
|
13
39
|
// transactional DDL, so we flip the flag — letting the Migrator wrap the whole
|
|
@@ -53,10 +79,10 @@ export function register(): void {}
|
|
|
53
79
|
export async function create(
|
|
54
80
|
resource: SqliteConnectionManifest,
|
|
55
81
|
_ctx: ResourceContext,
|
|
56
|
-
): Promise<
|
|
82
|
+
): Promise<SqliteConnection> {
|
|
57
83
|
const sqlite = await openSqliteDatabase(resource.file ?? ":memory:");
|
|
58
84
|
const db = new Kysely<any>({
|
|
59
85
|
dialect: new TransactionalSqliteDialect({ database: sqlite }),
|
|
60
86
|
});
|
|
61
|
-
return
|
|
87
|
+
return new SqliteConnection(db, sqlite);
|
|
62
88
|
}
|
package/src/sqlite-driver-bun.ts
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface SqliteStatement {
|
|
2
|
+
readonly reader: boolean;
|
|
3
|
+
all(params: ReadonlyArray<unknown>): unknown[];
|
|
4
|
+
run(params: ReadonlyArray<unknown>): {
|
|
5
|
+
changes: number | bigint;
|
|
6
|
+
lastInsertRowid: number | bigint;
|
|
7
|
+
};
|
|
8
|
+
iterate(params: ReadonlyArray<unknown>): IterableIterator<unknown>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface SqliteDb {
|
|
12
|
+
prepare(sql: string): SqliteStatement;
|
|
13
|
+
exec(sql: string): void;
|
|
14
|
+
close(): void;
|
|
15
|
+
}
|