cojson-storage-sqlite
Advanced tools
Comparing version
# cojson-storage-sqlite | ||
## 0.14.23 | ||
### Patch Changes | ||
- 5f42c97: Close the DB connection when the node/context is closed | ||
- Updated dependencies [1ca9299] | ||
- Updated dependencies [5f42c97] | ||
- cojson@0.14.23 | ||
- cojson-storage@0.14.23 | ||
## 0.14.22 | ||
@@ -4,0 +14,0 @@ |
@@ -9,3 +9,4 @@ import type { SQLiteDatabaseDriver } from "cojson-storage"; | ||
transaction(callback: () => unknown): unknown; | ||
closeDb(): void; | ||
} | ||
//# sourceMappingURL=betterSqliteDriver.d.ts.map |
@@ -20,3 +20,6 @@ import Database from "better-sqlite3"; | ||
} | ||
closeDb() { | ||
this.db.close(); | ||
} | ||
} | ||
//# sourceMappingURL=betterSqliteDriver.js.map |
@@ -6,5 +6,6 @@ import { randomUUID } from "node:crypto"; | ||
import { LocalNode, cojsonInternals } from "cojson"; | ||
import { StorageManagerSync } from "cojson-storage"; | ||
import { SQLiteNodeBase, StorageManagerSync } from "cojson-storage"; | ||
import { WasmCrypto } from "cojson/crypto/WasmCrypto"; | ||
import { expect, onTestFinished, test, vi } from "vitest"; | ||
import { BetterSqliteDriver } from "../betterSqliteDriver.js"; | ||
import { SQLiteNode } from "../index.js"; | ||
@@ -418,2 +419,21 @@ import { toSimplifiedMessages } from "./messagesTestUtils.js"; | ||
}); | ||
test("should close the db when the node is closed", async () => { | ||
const agentSecret = Crypto.newRandomAgentSecret(); | ||
const node1 = new LocalNode(agentSecret, Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret)), Crypto); | ||
const dbPath = join(tmpdir(), `test-${randomUUID()}.db`); | ||
const db = new BetterSqliteDriver(dbPath); | ||
const peer = SQLiteNodeBase.create({ | ||
db, | ||
localNodeName: "test", | ||
maxBlockingTime: 500, | ||
}); | ||
const spy = vi.spyOn(db, "closeDb"); | ||
node1.syncManager.addPeer(peer); | ||
await new Promise((resolve) => setTimeout(resolve, 10)); | ||
expect(spy).not.toHaveBeenCalled(); | ||
node1.gracefulShutdown(); | ||
await new Promise((resolve) => setTimeout(resolve, 10)); | ||
expect(spy).toHaveBeenCalled(); | ||
unlinkSync(dbPath); | ||
}); | ||
//# sourceMappingURL=storage.sqlite.test.js.map |
{ | ||
"name": "cojson-storage-sqlite", | ||
"type": "module", | ||
"version": "0.14.22", | ||
"version": "0.14.23", | ||
"main": "dist/index.js", | ||
@@ -10,4 +10,4 @@ "types": "dist/index.d.ts", | ||
"better-sqlite3": "^11.7.0", | ||
"cojson": "0.14.22", | ||
"cojson-storage": "0.14.22" | ||
"cojson": "0.14.23", | ||
"cojson-storage": "0.14.23" | ||
}, | ||
@@ -14,0 +14,0 @@ "devDependencies": { |
@@ -28,2 +28,6 @@ import Database, { type Database as DatabaseT } from "better-sqlite3"; | ||
} | ||
closeDb() { | ||
this.db.close(); | ||
} | ||
} |
@@ -6,5 +6,6 @@ import { randomUUID } from "node:crypto"; | ||
import { LocalNode, cojsonInternals } from "cojson"; | ||
import { StorageManagerSync } from "cojson-storage"; | ||
import { SQLiteNodeBase, StorageManagerSync } from "cojson-storage"; | ||
import { WasmCrypto } from "cojson/crypto/WasmCrypto"; | ||
import { expect, onTestFinished, test, vi } from "vitest"; | ||
import { BetterSqliteDriver } from "../betterSqliteDriver.js"; | ||
import { SQLiteNode } from "../index.js"; | ||
@@ -729,1 +730,37 @@ import { toSimplifiedMessages } from "./messagesTestUtils.js"; | ||
}); | ||
test("should close the db when the node is closed", async () => { | ||
const agentSecret = Crypto.newRandomAgentSecret(); | ||
const node1 = new LocalNode( | ||
agentSecret, | ||
Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret)), | ||
Crypto, | ||
); | ||
const dbPath = join(tmpdir(), `test-${randomUUID()}.db`); | ||
const db = new BetterSqliteDriver(dbPath); | ||
const peer = SQLiteNodeBase.create({ | ||
db, | ||
localNodeName: "test", | ||
maxBlockingTime: 500, | ||
}); | ||
const spy = vi.spyOn(db, "closeDb"); | ||
node1.syncManager.addPeer(peer); | ||
await new Promise((resolve) => setTimeout(resolve, 10)); | ||
expect(spy).not.toHaveBeenCalled(); | ||
node1.gracefulShutdown(); | ||
await new Promise((resolve) => setTimeout(resolve, 10)); | ||
expect(spy).toHaveBeenCalled(); | ||
unlinkSync(dbPath); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
92918
3.49%1372
3.86%+ Added
+ Added
- Removed
- Removed
Updated
Updated