jazz-react-native 0.14.16 → 0.14.18
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +22 -0
- package/dist/storage/op-sqlite-adapter.d.ts +6 -12
- package/dist/storage/op-sqlite-adapter.d.ts.map +1 -1
- package/dist/storage/op-sqlite-adapter.js +28 -105
- package/dist/storage/op-sqlite-adapter.js.map +1 -1
- package/package.json +5 -5
- package/src/storage/op-sqlite-adapter.ts +38 -135
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,27 @@
|
|
1
1
|
# jazz-browser
|
2
2
|
|
3
|
+
## 0.14.18
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- Updated dependencies [4b950bc]
|
8
|
+
- Updated dependencies [0d5ee3e]
|
9
|
+
- Updated dependencies [d6d9c0a]
|
10
|
+
- Updated dependencies [be7c4c2]
|
11
|
+
- Updated dependencies [c559054]
|
12
|
+
- jazz-tools@0.14.18
|
13
|
+
- jazz-react-native-core@0.14.18
|
14
|
+
- cojson@0.14.18
|
15
|
+
- cojson-storage@0.14.18
|
16
|
+
|
17
|
+
## 0.14.17
|
18
|
+
|
19
|
+
### Patch Changes
|
20
|
+
|
21
|
+
- Updated dependencies [e512df4]
|
22
|
+
- jazz-tools@0.14.17
|
23
|
+
- jazz-react-native-core@0.14.17
|
24
|
+
|
3
25
|
## 0.14.16
|
4
26
|
|
5
27
|
### Patch Changes
|
@@ -1,18 +1,12 @@
|
|
1
|
-
import
|
2
|
-
export declare class OPSQLiteAdapter implements
|
1
|
+
import { type SQLiteDatabaseDriverAsync } from "jazz-react-native-core";
|
2
|
+
export declare class OPSQLiteAdapter implements SQLiteDatabaseDriverAsync {
|
3
3
|
private db;
|
4
4
|
private dbName;
|
5
|
-
private dbPath;
|
6
|
-
private initializationPromise;
|
7
|
-
private isInitialized;
|
8
5
|
constructor(dbName?: string);
|
9
|
-
private initializeInternal;
|
10
|
-
private ensureInitialized;
|
11
6
|
initialize(): Promise<void>;
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
transaction(callback: () => Promise<void>): Promise<void>;
|
7
|
+
query<T>(sql: string, params?: unknown[]): Promise<T[]>;
|
8
|
+
get<T>(sql: string, params?: unknown[]): Promise<T | undefined>;
|
9
|
+
run(sql: string, params?: unknown[]): Promise<void>;
|
10
|
+
transaction(callback: () => unknown): Promise<void>;
|
17
11
|
}
|
18
12
|
//# sourceMappingURL=op-sqlite-adapter.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"op-sqlite-adapter.d.ts","sourceRoot":"","sources":["../../src/storage/op-sqlite-adapter.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"op-sqlite-adapter.d.ts","sourceRoot":"","sources":["../../src/storage/op-sqlite-adapter.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAExE,qBAAa,eAAgB,YAAW,yBAAyB;IAC/D,OAAO,CAAC,EAAE,CAA2B;IACrC,OAAO,CAAC,MAAM,CAAS;gBAEJ,MAAM,GAAE,MAAuB;IAIrC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3B,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAUvD,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAU/D,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE;IAQnC,WAAW,CAAC,QAAQ,EAAE,MAAM,OAAO;CAWjD"}
|
@@ -4,124 +4,47 @@ import { Platform } from "react-native";
|
|
4
4
|
export class OPSQLiteAdapter {
|
5
5
|
db = null;
|
6
6
|
dbName;
|
7
|
-
dbPath;
|
8
|
-
initializationPromise = null;
|
9
|
-
isInitialized = false;
|
10
7
|
constructor(dbName = "jazz-storage") {
|
11
8
|
this.dbName = dbName;
|
12
|
-
this.dbPath =
|
13
|
-
Platform.OS === "ios" ? IOS_LIBRARY_PATH : ANDROID_DATABASE_PATH;
|
14
9
|
}
|
15
|
-
async
|
16
|
-
|
17
|
-
|
18
|
-
this.
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
// Direct database operations during initialization - don't use execute()
|
23
|
-
const db = this.db;
|
24
|
-
if (!db)
|
25
|
-
throw new Error("Failed to open database");
|
26
|
-
await db.execute("PRAGMA journal_mode=WAL");
|
27
|
-
const { rows } = await db.execute("PRAGMA user_version");
|
28
|
-
const oldVersion = Number(rows[0]?.user_version) ?? 0;
|
29
|
-
if (oldVersion === 0) {
|
30
|
-
await db.execute(`CREATE TABLE IF NOT EXISTS transactions (
|
31
|
-
ses INTEGER,
|
32
|
-
idx INTEGER,
|
33
|
-
tx TEXT NOT NULL,
|
34
|
-
PRIMARY KEY (ses, idx)
|
35
|
-
) WITHOUT ROWID;`);
|
36
|
-
await db.execute(`CREATE TABLE IF NOT EXISTS sessions (
|
37
|
-
rowID INTEGER PRIMARY KEY,
|
38
|
-
coValue INTEGER NOT NULL,
|
39
|
-
sessionID TEXT NOT NULL,
|
40
|
-
lastIdx INTEGER,
|
41
|
-
lastSignature TEXT,
|
42
|
-
UNIQUE (sessionID, coValue)
|
43
|
-
);`);
|
44
|
-
await db.execute(`CREATE INDEX IF NOT EXISTS sessionsByCoValue ON sessions (coValue);`);
|
45
|
-
await db.execute(`CREATE TABLE IF NOT EXISTS coValues (
|
46
|
-
rowID INTEGER PRIMARY KEY,
|
47
|
-
id TEXT NOT NULL UNIQUE,
|
48
|
-
header TEXT NOT NULL UNIQUE
|
49
|
-
);`);
|
50
|
-
await db.execute(`CREATE INDEX IF NOT EXISTS coValuesByID ON coValues (id);`);
|
51
|
-
await db.execute("PRAGMA user_version = 1");
|
52
|
-
}
|
53
|
-
if (oldVersion <= 2) {
|
54
|
-
await db.execute(`CREATE TABLE IF NOT EXISTS signatureAfter (
|
55
|
-
ses INTEGER,
|
56
|
-
idx INTEGER,
|
57
|
-
signature TEXT NOT NULL,
|
58
|
-
PRIMARY KEY (ses, idx)
|
59
|
-
) WITHOUT ROWID;`);
|
60
|
-
await db.execute(`ALTER TABLE sessions ADD COLUMN bytesSinceLastSignature INTEGER;`);
|
61
|
-
await db.execute("PRAGMA user_version = 3");
|
62
|
-
}
|
63
|
-
console.log("[OPSQLiteAdapter] initialization complete");
|
64
|
-
}
|
65
|
-
catch (e) {
|
66
|
-
console.error("[OPSQLiteAdapter] initialization failed:", e);
|
67
|
-
throw new Error(`Failed to initialize OPSQLiteAdapter: ${e instanceof Error ? e.message : String(e)}`);
|
68
|
-
}
|
10
|
+
async initialize() {
|
11
|
+
const dbPath = Platform.OS === "ios" ? IOS_LIBRARY_PATH : ANDROID_DATABASE_PATH;
|
12
|
+
const db = (this.db = opSQLite.open({
|
13
|
+
name: this.dbName,
|
14
|
+
location: dbPath,
|
15
|
+
}));
|
16
|
+
await db.execute("PRAGMA journal_mode=WAL");
|
69
17
|
}
|
70
|
-
async
|
71
|
-
if (this.
|
72
|
-
|
73
|
-
if (!this.initializationPromise) {
|
74
|
-
this.initializationPromise = (async () => {
|
75
|
-
try {
|
76
|
-
await this.initializeInternal();
|
77
|
-
this.isInitialized = true;
|
78
|
-
}
|
79
|
-
catch (error) {
|
80
|
-
this.initializationPromise = null;
|
81
|
-
throw error;
|
82
|
-
}
|
83
|
-
})();
|
18
|
+
async query(sql, params) {
|
19
|
+
if (!this.db) {
|
20
|
+
throw new Error("Database not initialized");
|
84
21
|
}
|
85
|
-
await this.
|
22
|
+
const result = await this.db.execute(sql, params);
|
23
|
+
return result.rows;
|
86
24
|
}
|
87
|
-
async
|
88
|
-
|
25
|
+
async get(sql, params) {
|
26
|
+
if (!this.db) {
|
27
|
+
throw new Error("Database not initialized");
|
28
|
+
}
|
29
|
+
const result = await this.db.execute(sql, params);
|
30
|
+
return result.rows[0];
|
89
31
|
}
|
90
|
-
async
|
91
|
-
|
92
|
-
|
93
|
-
if (!db) {
|
94
|
-
throw new Error("Database not available after initialization");
|
32
|
+
async run(sql, params) {
|
33
|
+
if (!this.db) {
|
34
|
+
throw new Error("Database not initialized");
|
95
35
|
}
|
36
|
+
await this.db.executeRaw(sql, params);
|
37
|
+
}
|
38
|
+
async transaction(callback) {
|
39
|
+
await this.run("BEGIN TRANSACTION");
|
96
40
|
try {
|
97
|
-
|
98
|
-
|
99
|
-
rows: result.rows,
|
100
|
-
insertId: result.rowsAffected > 0
|
101
|
-
? result.rows[0]?.rowid
|
102
|
-
: undefined,
|
103
|
-
rowsAffected: result.rowsAffected,
|
104
|
-
};
|
41
|
+
await callback();
|
42
|
+
await this.run("COMMIT");
|
105
43
|
}
|
106
44
|
catch (error) {
|
107
|
-
|
45
|
+
await this.run("ROLLBACK");
|
108
46
|
throw error;
|
109
47
|
}
|
110
48
|
}
|
111
|
-
executeSync(sql, params) {
|
112
|
-
if (!this.isInitialized || !this.db) {
|
113
|
-
throw new Error("Database not initialized. Call initialize() first.");
|
114
|
-
}
|
115
|
-
const result = this.db.executeSync(sql, params);
|
116
|
-
return {
|
117
|
-
rows: result.rows,
|
118
|
-
};
|
119
|
-
}
|
120
|
-
async transaction(callback) {
|
121
|
-
if (!this.db) {
|
122
|
-
await this.ensureInitialized();
|
123
|
-
}
|
124
|
-
await this.db.transaction(callback);
|
125
|
-
}
|
126
49
|
}
|
127
50
|
//# sourceMappingURL=op-sqlite-adapter.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"op-sqlite-adapter.js","sourceRoot":"","sources":["../../src/storage/op-sqlite-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,2BAA2B,CAAC;AACtD,OAAO,EACL,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,2BAA2B,CAAC;
|
1
|
+
{"version":3,"file":"op-sqlite-adapter.js","sourceRoot":"","sources":["../../src/storage/op-sqlite-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,2BAA2B,CAAC;AACtD,OAAO,EACL,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAMxC,MAAM,OAAO,eAAe;IAClB,EAAE,GAAsB,IAAI,CAAC;IAC7B,MAAM,CAAS;IAEvB,YAAmB,SAAiB,cAAc;QAChD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEM,KAAK,CAAC,UAAU;QACrB,MAAM,MAAM,GACV,QAAQ,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,qBAAqB,CAAC;QAEnE,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC;YAClC,IAAI,EAAE,IAAI,CAAC,MAAM;YACjB,QAAQ,EAAE,MAAM;SACjB,CAAC,CAAC,CAAC;QAEJ,MAAM,EAAE,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAC9C,CAAC;IAEM,KAAK,CAAC,KAAK,CAAI,GAAW,EAAE,MAAkB;QACnD,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC9C,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,MAAe,CAAC,CAAC;QAE3D,OAAO,MAAM,CAAC,IAAW,CAAC;IAC5B,CAAC;IAEM,KAAK,CAAC,GAAG,CAAI,GAAW,EAAE,MAAkB;QACjD,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC9C,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,MAAe,CAAC,CAAC;QAE3D,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAkB,CAAC;IACzC,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,MAAkB;QAC9C,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC9C,CAAC;QAED,MAAM,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,MAAe,CAAC,CAAC;IACjD,CAAC;IAEM,KAAK,CAAC,WAAW,CAAC,QAAuB;QAC9C,MAAM,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAEpC,IAAI,CAAC;YACH,MAAM,QAAQ,EAAE,CAAC;YACjB,MAAM,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAC3B,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "jazz-react-native",
|
3
|
-
"version": "0.14.
|
3
|
+
"version": "0.14.18",
|
4
4
|
"type": "module",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"module": "./dist/index.js",
|
@@ -28,10 +28,10 @@
|
|
28
28
|
"@op-engineering/op-sqlite": "^11.4.8",
|
29
29
|
"@scure/base": "1.2.1",
|
30
30
|
"react-native-mmkv": "^3.2.0",
|
31
|
-
"cojson": "0.14.
|
32
|
-
"
|
33
|
-
"jazz-
|
34
|
-
"
|
31
|
+
"cojson": "0.14.18",
|
32
|
+
"cojson-storage": "0.14.18",
|
33
|
+
"jazz-react-native-core": "0.14.18",
|
34
|
+
"jazz-tools": "0.14.18"
|
35
35
|
},
|
36
36
|
"peerDependencies": {
|
37
37
|
"@react-native-community/netinfo": "*",
|
@@ -3,166 +3,69 @@ import {
|
|
3
3
|
ANDROID_DATABASE_PATH,
|
4
4
|
IOS_LIBRARY_PATH,
|
5
5
|
} from "@op-engineering/op-sqlite";
|
6
|
-
import type { SQLResult, SQLRow, SQLiteAdapter } from "jazz-react-native-core";
|
7
6
|
import { Platform } from "react-native";
|
8
7
|
|
9
8
|
type OPSQLiteDB = ReturnType<typeof opSQLite.open>;
|
10
9
|
|
11
|
-
|
10
|
+
import { type SQLiteDatabaseDriverAsync } from "jazz-react-native-core";
|
11
|
+
|
12
|
+
export class OPSQLiteAdapter implements SQLiteDatabaseDriverAsync {
|
12
13
|
private db: OPSQLiteDB | null = null;
|
13
14
|
private dbName: string;
|
14
|
-
private dbPath: string;
|
15
|
-
private initializationPromise: Promise<void> | null = null;
|
16
|
-
private isInitialized = false;
|
17
15
|
|
18
16
|
public constructor(dbName: string = "jazz-storage") {
|
19
17
|
this.dbName = dbName;
|
20
|
-
this.dbPath =
|
21
|
-
Platform.OS === "ios" ? IOS_LIBRARY_PATH : ANDROID_DATABASE_PATH;
|
22
18
|
}
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
if (!db) throw new Error("Failed to open database");
|
35
|
-
|
36
|
-
await db.execute("PRAGMA journal_mode=WAL");
|
37
|
-
const { rows } = await db.execute("PRAGMA user_version");
|
38
|
-
const oldVersion = Number(rows[0]?.user_version) ?? 0;
|
39
|
-
|
40
|
-
if (oldVersion === 0) {
|
41
|
-
await db.execute(
|
42
|
-
`CREATE TABLE IF NOT EXISTS transactions (
|
43
|
-
ses INTEGER,
|
44
|
-
idx INTEGER,
|
45
|
-
tx TEXT NOT NULL,
|
46
|
-
PRIMARY KEY (ses, idx)
|
47
|
-
) WITHOUT ROWID;`,
|
48
|
-
);
|
49
|
-
|
50
|
-
await db.execute(
|
51
|
-
`CREATE TABLE IF NOT EXISTS sessions (
|
52
|
-
rowID INTEGER PRIMARY KEY,
|
53
|
-
coValue INTEGER NOT NULL,
|
54
|
-
sessionID TEXT NOT NULL,
|
55
|
-
lastIdx INTEGER,
|
56
|
-
lastSignature TEXT,
|
57
|
-
UNIQUE (sessionID, coValue)
|
58
|
-
);`,
|
59
|
-
);
|
60
|
-
|
61
|
-
await db.execute(
|
62
|
-
`CREATE INDEX IF NOT EXISTS sessionsByCoValue ON sessions (coValue);`,
|
63
|
-
);
|
64
|
-
|
65
|
-
await db.execute(
|
66
|
-
`CREATE TABLE IF NOT EXISTS coValues (
|
67
|
-
rowID INTEGER PRIMARY KEY,
|
68
|
-
id TEXT NOT NULL UNIQUE,
|
69
|
-
header TEXT NOT NULL UNIQUE
|
70
|
-
);`,
|
71
|
-
);
|
72
|
-
|
73
|
-
await db.execute(
|
74
|
-
`CREATE INDEX IF NOT EXISTS coValuesByID ON coValues (id);`,
|
75
|
-
);
|
76
|
-
|
77
|
-
await db.execute("PRAGMA user_version = 1");
|
78
|
-
}
|
79
|
-
|
80
|
-
if (oldVersion <= 2) {
|
81
|
-
await db.execute(
|
82
|
-
`CREATE TABLE IF NOT EXISTS signatureAfter (
|
83
|
-
ses INTEGER,
|
84
|
-
idx INTEGER,
|
85
|
-
signature TEXT NOT NULL,
|
86
|
-
PRIMARY KEY (ses, idx)
|
87
|
-
) WITHOUT ROWID;`,
|
88
|
-
);
|
89
|
-
|
90
|
-
await db.execute(
|
91
|
-
`ALTER TABLE sessions ADD COLUMN bytesSinceLastSignature INTEGER;`,
|
92
|
-
);
|
93
|
-
|
94
|
-
await db.execute("PRAGMA user_version = 3");
|
95
|
-
}
|
96
|
-
|
97
|
-
console.log("[OPSQLiteAdapter] initialization complete");
|
98
|
-
} catch (e) {
|
99
|
-
console.error("[OPSQLiteAdapter] initialization failed:", e);
|
100
|
-
throw new Error(
|
101
|
-
`Failed to initialize OPSQLiteAdapter: ${e instanceof Error ? e.message : String(e)}`,
|
102
|
-
);
|
103
|
-
}
|
20
|
+
public async initialize(): Promise<void> {
|
21
|
+
const dbPath =
|
22
|
+
Platform.OS === "ios" ? IOS_LIBRARY_PATH : ANDROID_DATABASE_PATH;
|
23
|
+
|
24
|
+
const db = (this.db = opSQLite.open({
|
25
|
+
name: this.dbName,
|
26
|
+
location: dbPath,
|
27
|
+
}));
|
28
|
+
|
29
|
+
await db.execute("PRAGMA journal_mode=WAL");
|
104
30
|
}
|
105
31
|
|
106
|
-
|
107
|
-
if (this.
|
108
|
-
|
109
|
-
if (!this.initializationPromise) {
|
110
|
-
this.initializationPromise = (async () => {
|
111
|
-
try {
|
112
|
-
await this.initializeInternal();
|
113
|
-
this.isInitialized = true;
|
114
|
-
} catch (error) {
|
115
|
-
this.initializationPromise = null;
|
116
|
-
throw error;
|
117
|
-
}
|
118
|
-
})();
|
32
|
+
public async query<T>(sql: string, params?: unknown[]): Promise<T[]> {
|
33
|
+
if (!this.db) {
|
34
|
+
throw new Error("Database not initialized");
|
119
35
|
}
|
120
36
|
|
121
|
-
await this.
|
122
|
-
}
|
37
|
+
const result = await this.db.execute(sql, params as any[]);
|
123
38
|
|
124
|
-
|
125
|
-
await this.ensureInitialized();
|
39
|
+
return result.rows as T[];
|
126
40
|
}
|
127
41
|
|
128
|
-
public async
|
129
|
-
|
130
|
-
|
131
|
-
const db = this.db;
|
132
|
-
if (!db) {
|
133
|
-
throw new Error("Database not available after initialization");
|
42
|
+
public async get<T>(sql: string, params?: unknown[]): Promise<T | undefined> {
|
43
|
+
if (!this.db) {
|
44
|
+
throw new Error("Database not initialized");
|
134
45
|
}
|
135
46
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
rows: result.rows as SQLRow[],
|
140
|
-
insertId:
|
141
|
-
result.rowsAffected > 0
|
142
|
-
? (result.rows[0]?.rowid as number)
|
143
|
-
: undefined,
|
144
|
-
rowsAffected: result.rowsAffected,
|
145
|
-
};
|
146
|
-
} catch (error) {
|
147
|
-
console.error("[OPSQLiteAdapter] SQL execution error:", error);
|
148
|
-
throw error;
|
149
|
-
}
|
47
|
+
const result = await this.db.execute(sql, params as any[]);
|
48
|
+
|
49
|
+
return result.rows[0] as T | undefined;
|
150
50
|
}
|
151
51
|
|
152
|
-
public
|
153
|
-
if (!this.
|
154
|
-
throw new Error("Database not initialized
|
52
|
+
public async run(sql: string, params?: unknown[]) {
|
53
|
+
if (!this.db) {
|
54
|
+
throw new Error("Database not initialized");
|
155
55
|
}
|
156
|
-
|
157
|
-
|
158
|
-
rows: result.rows as SQLRow[],
|
159
|
-
};
|
56
|
+
|
57
|
+
await this.db.executeRaw(sql, params as any[]);
|
160
58
|
}
|
161
59
|
|
162
|
-
public async transaction(callback: () =>
|
163
|
-
|
164
|
-
|
60
|
+
public async transaction(callback: () => unknown) {
|
61
|
+
await this.run("BEGIN TRANSACTION");
|
62
|
+
|
63
|
+
try {
|
64
|
+
await callback();
|
65
|
+
await this.run("COMMIT");
|
66
|
+
} catch (error) {
|
67
|
+
await this.run("ROLLBACK");
|
68
|
+
throw error;
|
165
69
|
}
|
166
|
-
await this.db!.transaction(callback);
|
167
70
|
}
|
168
71
|
}
|