@shetty4l/core 0.1.38 → 0.1.39
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/package.json +1 -1
- package/src/db.ts +1 -0
- package/src/state/loader.ts +4 -3
package/package.json
CHANGED
package/src/db.ts
CHANGED
|
@@ -77,6 +77,7 @@ export function createDatabaseManager(opts: DatabaseOpts): DatabaseManager {
|
|
|
77
77
|
// Enable WAL mode for better concurrent access (not applicable to :memory:)
|
|
78
78
|
if (path !== ":memory:") {
|
|
79
79
|
db.exec("PRAGMA journal_mode = WAL;");
|
|
80
|
+
db.exec("PRAGMA busy_timeout = 5000;");
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
// Execute schema SQL
|
package/src/state/loader.ts
CHANGED
|
@@ -538,8 +538,9 @@ export class StateLoader {
|
|
|
538
538
|
/**
|
|
539
539
|
* Execute a function within a database transaction.
|
|
540
540
|
*
|
|
541
|
-
* Uses BEGIN
|
|
542
|
-
*
|
|
541
|
+
* Uses BEGIN DEFERRED to defer lock acquisition until the first write.
|
|
542
|
+
* This allows concurrent readers and writers with WAL mode.
|
|
543
|
+
* If the function throws, the transaction is rolled back.
|
|
543
544
|
* Otherwise, it is committed.
|
|
544
545
|
*
|
|
545
546
|
* @param fn - The function to execute within the transaction
|
|
@@ -559,7 +560,7 @@ export class StateLoader {
|
|
|
559
560
|
* ```
|
|
560
561
|
*/
|
|
561
562
|
async transaction<T>(fn: () => T | Promise<T>): Promise<T> {
|
|
562
|
-
this.db.exec("BEGIN
|
|
563
|
+
this.db.exec("BEGIN DEFERRED");
|
|
563
564
|
try {
|
|
564
565
|
const result = await fn();
|
|
565
566
|
this.db.exec("COMMIT");
|