@smart-db/sqlite-node 0.1.2
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/async.d.ts +2 -0
- package/dist/async.js +48 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/sync.d.ts +2 -0
- package/dist/sync.js +36 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +7 -0
- package/package.json +44 -0
package/dist/async.d.ts
ADDED
package/dist/async.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import NodeDatabase from "better-sqlite3";
|
|
2
|
+
import { getArgs } from "./utils.js";
|
|
3
|
+
export function createAsync(dbPath) {
|
|
4
|
+
const db = new NodeDatabase(dbPath);
|
|
5
|
+
async function run(sql, params) {
|
|
6
|
+
const info = db.prepare(sql).run(...getArgs(params));
|
|
7
|
+
return {
|
|
8
|
+
changes: info.changes,
|
|
9
|
+
lastInsertRowid: Number(info.lastInsertRowid)
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
async function all(sql, params) {
|
|
13
|
+
return db.prepare(sql).all(...getArgs(params));
|
|
14
|
+
}
|
|
15
|
+
async function get(sql, params) {
|
|
16
|
+
const result = db.prepare(sql).get(...getArgs(params));
|
|
17
|
+
return result ?? undefined;
|
|
18
|
+
}
|
|
19
|
+
async function first(sql, params) {
|
|
20
|
+
return get(sql, params);
|
|
21
|
+
}
|
|
22
|
+
async function value(sql, params) {
|
|
23
|
+
const result = db.prepare(sql).pluck(true).get(...getArgs(params));
|
|
24
|
+
return result ?? undefined;
|
|
25
|
+
}
|
|
26
|
+
async function pluck(sql, params) {
|
|
27
|
+
return db.prepare(sql).pluck(true).all(...getArgs(params));
|
|
28
|
+
}
|
|
29
|
+
function transaction(callback) {
|
|
30
|
+
const wrappedFunction = async (...args) => {
|
|
31
|
+
db.exec("BEGIN TRANSACTION");
|
|
32
|
+
try {
|
|
33
|
+
const result = await callback(...args);
|
|
34
|
+
db.exec("COMMIT");
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
db.exec("ROLLBACK");
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
return wrappedFunction;
|
|
43
|
+
}
|
|
44
|
+
async function close() {
|
|
45
|
+
db.close();
|
|
46
|
+
}
|
|
47
|
+
return { run, all, get, first, value, pluck, transaction, close };
|
|
48
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/sync.d.ts
ADDED
package/dist/sync.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import NodeDatabase from "better-sqlite3";
|
|
2
|
+
import { getArgs } from "./utils.js";
|
|
3
|
+
export function createSync(dbPath) {
|
|
4
|
+
const db = new NodeDatabase(dbPath);
|
|
5
|
+
function run(sql, params) {
|
|
6
|
+
const info = db.prepare(sql).run(...getArgs(params));
|
|
7
|
+
return {
|
|
8
|
+
changes: info.changes,
|
|
9
|
+
lastInsertRowid: Number(info.lastInsertRowid)
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function all(sql, params) {
|
|
13
|
+
return db.prepare(sql).all(...getArgs(params));
|
|
14
|
+
}
|
|
15
|
+
function get(sql, params) {
|
|
16
|
+
const result = db.prepare(sql).get(...getArgs(params));
|
|
17
|
+
return result ?? undefined;
|
|
18
|
+
}
|
|
19
|
+
function first(sql, params) {
|
|
20
|
+
return get(sql, params);
|
|
21
|
+
}
|
|
22
|
+
function value(sql, params) {
|
|
23
|
+
const result = db.prepare(sql).pluck(true).get(...getArgs(params));
|
|
24
|
+
return result ?? undefined;
|
|
25
|
+
}
|
|
26
|
+
function pluck(sql, params) {
|
|
27
|
+
return db.prepare(sql).pluck(true).all(...getArgs(params));
|
|
28
|
+
}
|
|
29
|
+
function transaction(callback) {
|
|
30
|
+
return db.transaction(callback);
|
|
31
|
+
}
|
|
32
|
+
function close() {
|
|
33
|
+
db.close();
|
|
34
|
+
}
|
|
35
|
+
return { run, all, get, first, value, pluck, transaction, close };
|
|
36
|
+
}
|
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@smart-db/sqlite-node",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Node.js better-sqlite3 adapter for the smart-db ecosystem",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/smart-db/smart-db.git",
|
|
8
|
+
"directory": "packages/sqlite-node"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/smart-db/smart-db/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/smart-db/smart-db#readme",
|
|
14
|
+
"author": "Martin Winkler",
|
|
15
|
+
"keywords": [],
|
|
16
|
+
"main": "dist/index.js",
|
|
17
|
+
"types": "dist/index.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc",
|
|
30
|
+
"prepublishOnly": "bun run build",
|
|
31
|
+
"test": "vitest run"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@smart-db/core": "^0.1.1",
|
|
38
|
+
"better-sqlite3": "^12.11.1"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/better-sqlite3": "^7.6.10"
|
|
43
|
+
}
|
|
44
|
+
}
|