@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shetty4l/core",
3
- "version": "0.1.38",
3
+ "version": "0.1.39",
4
4
  "description": "Shared infrastructure primitives for Bun/TypeScript services",
5
5
  "repository": {
6
6
  "type": "git",
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
@@ -538,8 +538,9 @@ export class StateLoader {
538
538
  /**
539
539
  * Execute a function within a database transaction.
540
540
  *
541
- * Uses BEGIN IMMEDIATE to acquire a write lock immediately, preventing
542
- * other writers. If the function throws, the transaction is rolled back.
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 IMMEDIATE");
563
+ this.db.exec("BEGIN DEFERRED");
563
564
  try {
564
565
  const result = await fn();
565
566
  this.db.exec("COMMIT");