zam-core 0.3.0 → 0.3.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/cli/index.js +10 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/kernel/db/connection.ts
|
|
2
2
|
import Database from "libsql";
|
|
3
|
-
import { existsSync, mkdirSync } from "fs";
|
|
3
|
+
import { existsSync, mkdirSync, rmSync } from "fs";
|
|
4
4
|
import { homedir } from "os";
|
|
5
5
|
import { dirname, join } from "path";
|
|
6
6
|
|
|
@@ -128,6 +128,13 @@ function openDatabase(options = {}) {
|
|
|
128
128
|
const dbOpts = {};
|
|
129
129
|
if (options.syncUrl) {
|
|
130
130
|
dbOpts.syncUrl = options.syncUrl;
|
|
131
|
+
const metaPath = `${dbPath}.meta`;
|
|
132
|
+
if (existsSync(dbPath) && !existsSync(metaPath)) {
|
|
133
|
+
for (const suffix of ["", "-wal", "-shm"]) {
|
|
134
|
+
const f = `${dbPath}${suffix}`;
|
|
135
|
+
if (existsSync(f)) rmSync(f);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
131
138
|
}
|
|
132
139
|
if (options.authToken) {
|
|
133
140
|
dbOpts.authToken = options.authToken;
|
|
@@ -150,6 +157,8 @@ function openDatabaseWithSync(options = {}) {
|
|
|
150
157
|
const syncUrl = db.prepare("SELECT value FROM user_config WHERE key = ?").get("turso.url");
|
|
151
158
|
const authToken = db.prepare("SELECT value FROM user_config WHERE key = ?").get("turso.token");
|
|
152
159
|
if (!syncUrl || !authToken) return db;
|
|
160
|
+
db.pragma("wal_checkpoint(TRUNCATE)");
|
|
161
|
+
db.pragma("journal_mode = DELETE");
|
|
153
162
|
db.close();
|
|
154
163
|
return openDatabase({ ...options, syncUrl: syncUrl.value, authToken: authToken.value });
|
|
155
164
|
}
|