@mcoda/db 0.1.4

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.
@@ -0,0 +1,12 @@
1
+ import { Database } from "sqlite";
2
+ export declare class Connection {
3
+ private database;
4
+ readonly dbPath: string;
5
+ constructor(database: Database, dbPath: string);
6
+ get db(): Database;
7
+ static open(dbPath: string): Promise<Connection>;
8
+ static openGlobal(): Promise<Connection>;
9
+ static openWorkspace(cwd?: string): Promise<Connection>;
10
+ close(): Promise<void>;
11
+ }
12
+ //# sourceMappingURL=connection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/sqlite/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAQ,MAAM,QAAQ,CAAC;AAMxC,qBAAa,UAAU;IACT,OAAO,CAAC,QAAQ;aAA4B,MAAM,EAAE,MAAM;gBAAlD,QAAQ,EAAE,QAAQ,EAAkB,MAAM,EAAE,MAAM;IAEtE,IAAI,EAAE,IAAI,QAAQ,CAEjB;WAEY,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;WAUzC,UAAU,IAAI,OAAO,CAAC,UAAU,CAAC;WAIjC,aAAa,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAIvD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
@@ -0,0 +1,32 @@
1
+ import { open } from "sqlite";
2
+ import sqlite3 from "sqlite3";
3
+ import { PathHelper } from "@mcoda/shared";
4
+ import { Pragmas } from "./pragmas.js";
5
+ import path from "node:path";
6
+ export class Connection {
7
+ constructor(database, dbPath) {
8
+ this.database = database;
9
+ this.dbPath = dbPath;
10
+ }
11
+ get db() {
12
+ return this.database;
13
+ }
14
+ static async open(dbPath) {
15
+ await PathHelper.ensureDir(path.dirname(dbPath));
16
+ const database = await open({
17
+ filename: dbPath,
18
+ driver: sqlite3.Database,
19
+ });
20
+ await Pragmas.apply(database);
21
+ return new Connection(database, dbPath);
22
+ }
23
+ static async openGlobal() {
24
+ return this.open(PathHelper.getGlobalDbPath());
25
+ }
26
+ static async openWorkspace(cwd) {
27
+ return this.open(PathHelper.getWorkspaceDbPath(cwd));
28
+ }
29
+ async close() {
30
+ await this.database.close();
31
+ }
32
+ }
@@ -0,0 +1,5 @@
1
+ import { Database } from "sqlite";
2
+ export declare class Pragmas {
3
+ static apply(db: Database): Promise<void>;
4
+ }
5
+ //# sourceMappingURL=pragmas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pragmas.d.ts","sourceRoot":"","sources":["../../src/sqlite/pragmas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,qBAAa,OAAO;WACL,KAAK,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CAMhD"}
@@ -0,0 +1,8 @@
1
+ export class Pragmas {
2
+ static async apply(db) {
3
+ await db.exec("PRAGMA foreign_keys = ON;");
4
+ await db.exec("PRAGMA journal_mode = WAL;");
5
+ await db.exec("PRAGMA synchronous = NORMAL;");
6
+ await db.exec("PRAGMA busy_timeout = 30000;");
7
+ }
8
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@mcoda/db",
3
+ "version": "0.1.4",
4
+ "description": "SQLite-backed storage layer for mcoda.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "!dist/**/__tests__/**",
11
+ "!dist/**/*.test.*",
12
+ "README.md",
13
+ "CHANGELOG.md",
14
+ "LICENSE"
15
+ ],
16
+ "scripts": {
17
+ "build": "tsc -p tsconfig.json",
18
+ "lint": "echo \"lint not configured\"",
19
+ "test": "pnpm run build && node ../../scripts/run-node-tests.js dist"
20
+ },
21
+ "engines": {
22
+ "node": ">=20"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/bekirdag/mcoda.git"
27
+ },
28
+ "bugs": {
29
+ "url": "https://github.com/bekirdag/mcoda/issues"
30
+ },
31
+ "homepage": "https://github.com/bekirdag/mcoda#readme",
32
+ "license": "MIT",
33
+ "author": "bekir dag",
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "dependencies": {
38
+ "@mcoda/shared": "workspace:*",
39
+ "sqlite": "^5.1.1",
40
+ "sqlite3": "^5.1.7"
41
+ }
42
+ }