@iamkirbki/database-handler-better-sqlite3 2.0.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/BetterSqlite3Adapter.d.ts +11 -0
- package/dist/BetterSqlite3Adapter.d.ts.map +1 -0
- package/dist/BetterSqlite3Adapter.js +76 -0
- package/dist/BetterSqlite3Statement.d.ts +11 -0
- package/dist/BetterSqlite3Statement.d.ts.map +1 -0
- package/dist/BetterSqlite3Statement.js +33 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/package.json +37 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IDatabaseAdapter, IStatementAdapter, TableColumnInfo } from "@iamkirbki/database-handler-core";
|
|
2
|
+
export default class BetterSqlite3Adapter implements IDatabaseAdapter {
|
|
3
|
+
private db;
|
|
4
|
+
connect(databasePath: string): Promise<void>;
|
|
5
|
+
prepare(query: string): Promise<IStatementAdapter>;
|
|
6
|
+
exec(query: string): Promise<void>;
|
|
7
|
+
transaction(fn: (items: unknown[]) => void): Promise<Function>;
|
|
8
|
+
tableColumnInformation(tableName: string): Promise<TableColumnInfo[]>;
|
|
9
|
+
close(): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=BetterSqlite3Adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BetterSqlite3Adapter.d.ts","sourceRoot":"","sources":["../src/BetterSqlite3Adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAIxG,MAAM,CAAC,OAAO,OAAO,oBAAqB,YAAW,gBAAgB;IACjE,OAAO,CAAC,EAAE,CAAkC;IAEtC,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO5C,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAQlD,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASlC,WAAW,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC;IAQ9D,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAkBrE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAS/B"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import Database from "better-sqlite3";
|
|
11
|
+
import BetterSqlite3Statement from "./BetterSqlite3Statement";
|
|
12
|
+
export default class BetterSqlite3Adapter {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.db = null;
|
|
15
|
+
}
|
|
16
|
+
connect(databasePath) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
if (this.db) {
|
|
19
|
+
throw new Error("Database is already connected.");
|
|
20
|
+
}
|
|
21
|
+
this.db = new Database(databasePath);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
prepare(query) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
if (!this.db) {
|
|
27
|
+
throw new Error("Database is not connected.");
|
|
28
|
+
}
|
|
29
|
+
const stmt = this.db.prepare(query);
|
|
30
|
+
return new BetterSqlite3Statement(stmt);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
exec(query) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
if (!this.db) {
|
|
36
|
+
throw new Error("Database is not connected.");
|
|
37
|
+
}
|
|
38
|
+
this.db.exec(query);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
// eslint-disable-next-line no-unused-vars
|
|
42
|
+
transaction(fn) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
if (!this.db) {
|
|
45
|
+
throw new Error("Database is not connected.");
|
|
46
|
+
}
|
|
47
|
+
return this.db.transaction(fn);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
tableColumnInformation(tableName) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
if (!this.db) {
|
|
53
|
+
throw new Error("Database is not connected.");
|
|
54
|
+
}
|
|
55
|
+
const stmt = this.db.prepare(`PRAGMA table_info(${tableName})`);
|
|
56
|
+
const rows = stmt.all();
|
|
57
|
+
return rows.map((row) => ({
|
|
58
|
+
cid: row.cid,
|
|
59
|
+
name: row.name,
|
|
60
|
+
type: row.type,
|
|
61
|
+
notnull: row.notnull,
|
|
62
|
+
dflt_value: row.dflt_value,
|
|
63
|
+
pk: row.pk
|
|
64
|
+
}));
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
close() {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
if (!this.db) {
|
|
70
|
+
throw new Error("Database is not connected.");
|
|
71
|
+
}
|
|
72
|
+
this.db.close();
|
|
73
|
+
this.db = null;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RunResult, Statement } from "better-sqlite3";
|
|
2
|
+
import { IStatementAdapter } from "@iamkirbki/database-handler-core";
|
|
3
|
+
export default class BetterSqlite3Statement implements IStatementAdapter {
|
|
4
|
+
private stmt;
|
|
5
|
+
constructor(stmt: Statement);
|
|
6
|
+
run(parameters?: object): Promise<RunResult>;
|
|
7
|
+
all(parameters?: object): Promise<unknown[]>;
|
|
8
|
+
get(parameters?: object): Promise<unknown | undefined>;
|
|
9
|
+
runSync(parameters?: object): RunResult;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=BetterSqlite3Statement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BetterSqlite3Statement.d.ts","sourceRoot":"","sources":["../src/BetterSqlite3Statement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAErE,MAAM,CAAC,OAAO,OAAO,sBAAuB,YAAW,iBAAiB;IACpE,OAAO,CAAC,IAAI,CAAY;gBAEZ,IAAI,EAAE,SAAS;IAIrB,GAAG,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAI5C,GAAG,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAI5C,GAAG,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;IAK5D,OAAO,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS;CAG1C"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export default class BetterSqlite3Statement {
|
|
11
|
+
constructor(stmt) {
|
|
12
|
+
this.stmt = stmt;
|
|
13
|
+
}
|
|
14
|
+
run(parameters) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
return parameters ? this.stmt.run(parameters) : this.stmt.run();
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
all(parameters) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
return parameters ? this.stmt.all(parameters) : this.stmt.all();
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
get(parameters) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
return parameters ? this.stmt.get(parameters) : this.stmt.get();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
// Synchronous version for use in transactions
|
|
30
|
+
runSync(parameters) {
|
|
31
|
+
return parameters ? this.stmt.run(parameters) : this.stmt.run();
|
|
32
|
+
}
|
|
33
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAG5D,qBAAa,qBAAsB,SAAQ,QAAQ;gBACrC,MAAM,EAAE,MAAM;CAK3B"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Database } from "@iamkirbki/database-handler-core";
|
|
2
|
+
import BetterSqlite3Adapter from "./BetterSqlite3Adapter";
|
|
3
|
+
export class BetterSqlite3Database extends Database {
|
|
4
|
+
constructor(dbPath) {
|
|
5
|
+
const adapter = new BetterSqlite3Adapter();
|
|
6
|
+
adapter.connect(dbPath);
|
|
7
|
+
super(adapter);
|
|
8
|
+
}
|
|
9
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@iamkirbki/database-handler-better-sqlite3",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"author": "iamkirbki",
|
|
5
|
+
"description": "Better-sqlite3 adapter for @kirbkis-database-handler/core",
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"module": "dist/index.js",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"keywords": [
|
|
15
|
+
"database",
|
|
16
|
+
"sqlite",
|
|
17
|
+
"better-sqlite3",
|
|
18
|
+
"orm",
|
|
19
|
+
"typescript"
|
|
20
|
+
],
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/IamKirbki/bettersqlite3-handler.git",
|
|
24
|
+
"directory": "packages/better-sqlite3"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsc"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@iamkirbki/database-handler-core": "^2.0.0",
|
|
31
|
+
"better-sqlite3": "^11.10.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/better-sqlite3": "^7.6.13",
|
|
35
|
+
"typescript": "^5.9.3"
|
|
36
|
+
}
|
|
37
|
+
}
|