@arcote.tech/arc-adapter-db-sqlite 0.3.1 → 0.3.3
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 +4108 -0
- package/package.json +4 -1
- package/src/bun-sqlite.ts +0 -82
- package/src/index.ts +0 -3
- package/src/sqlite-adapter.ts +0 -812
- package/tsconfig.json +0 -11
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcote.tech/arc-adapter-db-sqlite",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
7
10
|
"exports": {
|
|
8
11
|
".": {
|
|
9
12
|
"import": "./dist/index.js",
|
package/src/bun-sqlite.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type { ArcContextAny, DBAdapterFactory } from "@arcote.tech/arc";
|
|
2
|
-
import { Database } from "bun:sqlite";
|
|
3
|
-
import type { SQLiteDatabase } from "./sqlite-adapter";
|
|
4
|
-
import { createSQLiteAdapterFactory } from "./sqlite-adapter";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Bun SQLite wrapper that implements SQLiteDatabase interface
|
|
8
|
-
*/
|
|
9
|
-
export class BunSQLiteDatabase implements SQLiteDatabase {
|
|
10
|
-
private db: Database;
|
|
11
|
-
|
|
12
|
-
constructor(filename: string = ":memory:") {
|
|
13
|
-
this.db = new Database(filename);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async exec(sql: string, params?: any[]): Promise<any[]> {
|
|
17
|
-
try {
|
|
18
|
-
if (params && params.length > 0) {
|
|
19
|
-
const stmt = this.db.prepare(sql);
|
|
20
|
-
if (sql.trim().toUpperCase().startsWith("SELECT")) {
|
|
21
|
-
return stmt.all(...params) as any[];
|
|
22
|
-
} else {
|
|
23
|
-
stmt.run(...params);
|
|
24
|
-
return [];
|
|
25
|
-
}
|
|
26
|
-
} else {
|
|
27
|
-
const statements = sql.split(";").filter((s) => s.trim());
|
|
28
|
-
let result: any[] = [];
|
|
29
|
-
|
|
30
|
-
for (const statement of statements) {
|
|
31
|
-
if (!statement.trim()) continue;
|
|
32
|
-
|
|
33
|
-
if (statement.trim().toUpperCase().startsWith("SELECT")) {
|
|
34
|
-
result = this.db.prepare(statement).all() as any[];
|
|
35
|
-
} else {
|
|
36
|
-
this.db.exec(statement);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
} catch (error) {
|
|
42
|
-
console.error("SQL Error:", error, "\nSQL:", sql, "\nParams:", params);
|
|
43
|
-
throw error;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async execBatch(
|
|
48
|
-
queries: Array<{ sql: string; params?: any[] }>,
|
|
49
|
-
): Promise<void> {
|
|
50
|
-
this.db.exec("BEGIN TRANSACTION");
|
|
51
|
-
try {
|
|
52
|
-
for (const query of queries) {
|
|
53
|
-
if (query.params && query.params.length > 0) {
|
|
54
|
-
this.db.prepare(query.sql).run(...query.params);
|
|
55
|
-
} else {
|
|
56
|
-
this.db.exec(query.sql);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
this.db.exec("COMMIT");
|
|
60
|
-
} catch (error) {
|
|
61
|
-
this.db.exec("ROLLBACK");
|
|
62
|
-
throw error;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
close() {
|
|
67
|
-
this.db.close();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Create a Bun SQLite adapter factory
|
|
73
|
-
* @param filename - Database filename, defaults to ":memory:" for in-memory database
|
|
74
|
-
*/
|
|
75
|
-
export const createBunSQLiteAdapterFactory = (
|
|
76
|
-
filename: string = ":memory:",
|
|
77
|
-
): DBAdapterFactory => {
|
|
78
|
-
return async (context: ArcContextAny) => {
|
|
79
|
-
const db = new BunSQLiteDatabase(filename);
|
|
80
|
-
return createSQLiteAdapterFactory(db)(context);
|
|
81
|
-
};
|
|
82
|
-
};
|
package/src/index.ts
DELETED