sqlite updates
authorJustin Wind <justin.wind+git@gmail.com>
Sat, 14 Jun 2025 19:15:10 +0000 (12:15 -0700)
committerJustin Wind <justin.wind+git@gmail.com>
Sat, 14 Jun 2025 19:15:10 +0000 (12:15 -0700)
package-lock.json
package.json
src/db/sqlite/index.js

index 8b376f1f404027008b1fb6afc67d6367f1a822eb..e47bc80e1094e3d4ef01a3616301591a10ec39c6 100644 (file)
         "@squeep/api-dingus": "^2",
         "@squeep/logger-json-console": "^3",
         "argon2": "^0.43.0",
-        "better-sqlite3": "^9.4.3",
+        "better-sqlite3": "^11",
         "pg-promise": "^11",
         "pm2": "^6",
         "uuid": "^11"
       },
       "devDependencies": {
-        "@squeep/eslint-config": "^1.0.2",
+        "@squeep/eslint-config": "^1",
         "eslint": "^9",
         "husky": "^9.1.7",
         "mocha": "^11",
         "url": "https://opencollective.com/eslint"
       }
     },
+    "node_modules/@eslint/eslintrc/node_modules/globals": {
+      "version": "14.0.0",
+      "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz",
+      "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==",
+      "dev": true,
+      "engines": {
+        "node": ">=18"
+      },
+      "funding": {
+        "url": "https://github.com/sponsors/sindresorhus"
+      }
+    },
     "node_modules/@eslint/js": {
       "version": "9.29.0",
       "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.29.0.tgz",
         "eslint": ">= 9"
       }
     },
-    "node_modules/@squeep/eslint-config/node_modules/eslint-plugin-sonarjs": {
-      "version": "1.0.4",
-      "resolved": "https://registry.npmjs.org/eslint-plugin-sonarjs/-/eslint-plugin-sonarjs-1.0.4.tgz",
-      "integrity": "sha512-jF0eGCUsq/HzMub4ExAyD8x1oEgjOyB9XVytYGyWgSFvdiJQJp6IuP7RmtauCf06o6N/kZErh+zW4b10y1WZ+Q==",
-      "dev": true,
-      "engines": {
-        "node": ">=16"
-      },
-      "peerDependencies": {
-        "eslint": "^8.0.0 || ^9.0.0"
-      }
-    },
-    "node_modules/@squeep/eslint-config/node_modules/globals": {
-      "version": "15.15.0",
-      "resolved": "https://registry.npmjs.org/globals/-/globals-15.15.0.tgz",
-      "integrity": "sha512-7ACyT3wmyp3I61S4fG682L0VA2RGD9otkqGJIwNUMF1SWUombIIk+af1unuDYgMm082aHYwD+mzJvv9Iu8dsgg==",
-      "dev": true,
-      "engines": {
-        "node": ">=18"
-      },
-      "funding": {
-        "url": "https://github.com/sponsors/sindresorhus"
-      }
-    },
     "node_modules/@squeep/log-helper": {
       "version": "1.0.1",
       "resolved": "https://registry.npmjs.org/@squeep/log-helper/-/log-helper-1.0.1.tgz",
       }
     },
     "node_modules/better-sqlite3": {
-      "version": "9.6.0",
-      "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-9.6.0.tgz",
-      "integrity": "sha512-yR5HATnqeYNVnkaUTf4bOP2dJSnyhP4puJN/QPRyx4YkBEEUxib422n2XzPqDEHjQQqazoYoADdAm5vE15+dAQ==",
+      "version": "11.10.0",
+      "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-11.10.0.tgz",
+      "integrity": "sha512-EwhOpyXiOEL/lKzHz9AW1msWFNzGc/z+LzeB3/jnFJpxu+th2yqvzsSWas1v9jgs9+xiXJcD5A8CJxAG2TaghQ==",
       "hasInstallScript": true,
       "dependencies": {
         "bindings": "^1.5.0",
         "balanced-match": "^1.0.0"
       }
     },
-    "node_modules/eslint-plugin-n/node_modules/globals": {
-      "version": "15.15.0",
-      "resolved": "https://registry.npmjs.org/globals/-/globals-15.15.0.tgz",
-      "integrity": "sha512-7ACyT3wmyp3I61S4fG682L0VA2RGD9otkqGJIwNUMF1SWUombIIk+af1unuDYgMm082aHYwD+mzJvv9Iu8dsgg==",
-      "dev": true,
-      "engines": {
-        "node": ">=18"
-      },
-      "funding": {
-        "url": "https://github.com/sponsors/sindresorhus"
-      }
-    },
     "node_modules/eslint-plugin-n/node_modules/minimatch": {
       "version": "9.0.5",
       "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz",
         "url": "https://opencollective.com/eslint"
       }
     },
+    "node_modules/eslint-plugin-sonarjs": {
+      "version": "1.0.4",
+      "resolved": "https://registry.npmjs.org/eslint-plugin-sonarjs/-/eslint-plugin-sonarjs-1.0.4.tgz",
+      "integrity": "sha512-jF0eGCUsq/HzMub4ExAyD8x1oEgjOyB9XVytYGyWgSFvdiJQJp6IuP7RmtauCf06o6N/kZErh+zW4b10y1WZ+Q==",
+      "dev": true,
+      "engines": {
+        "node": ">=16"
+      },
+      "peerDependencies": {
+        "eslint": "^8.0.0 || ^9.0.0"
+      }
+    },
     "node_modules/eslint-scope": {
       "version": "8.4.0",
       "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.4.0.tgz",
       }
     },
     "node_modules/globals": {
-      "version": "14.0.0",
-      "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz",
-      "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==",
+      "version": "15.15.0",
+      "resolved": "https://registry.npmjs.org/globals/-/globals-15.15.0.tgz",
+      "integrity": "sha512-7ACyT3wmyp3I61S4fG682L0VA2RGD9otkqGJIwNUMF1SWUombIIk+af1unuDYgMm082aHYwD+mzJvv9Iu8dsgg==",
       "dev": true,
       "engines": {
         "node": ">=18"
index 9535b5dea3fdebed89cf88420b702f710a5017cb..bf6c526b612c72dccfdffb5ae9b0247cd8bb7d65 100644 (file)
     "@squeep/api-dingus": "^2",
     "@squeep/logger-json-console": "^3",
     "argon2": "^0.43.0",
-    "better-sqlite3": "^9.4.3",
+    "better-sqlite3": "^11",
     "pg-promise": "^11",
     "pm2": "^6",
     "uuid": "^11"
   },
   "devDependencies": {
-    "@squeep/eslint-config": "^1.0.2",
+    "@squeep/eslint-config": "^1",
     "eslint": "^9",
-    "husky": "^9.1.7",
+    "husky": "^9",
     "mocha": "^11",
     "nyc": "^17",
     "sinon": "^21"
index 67c1f788c0b9f0f7a81372e38ff1eeb91a6d4309..39b9b6b1250b6bb6d21c744c318c7ff34440820e 100644 (file)
@@ -1,7 +1,6 @@
 'use strict';
 
 const SQLite = require('better-sqlite3');
-// XXX: const NodeCleanup = require('node-cleanup');
 const BaseDatabase = require('../base');
 const common = require('../../common');
 const DBErrors = require('../errors');
@@ -33,13 +32,6 @@ class SQLiteDatabase extends BaseDatabase {
 
     this.changesSinceLastOptimize = BigInt(0);
 
-    /*
-    NodeCleanup(() => {
-      this._optimize();
-      this._closeConnection();
-    });
-    */
-
     this.db.pragma('foreign_keys = on');
     this.db.pragma('journal_mode = WAL');
     this.db.defaultSafeIntegers(true);
@@ -97,6 +89,9 @@ class SQLiteDatabase extends BaseDatabase {
 
   _initStatements() {
     this.statement = {
+      _beginImmediate: this.db.prepare('BEGIN IMMEDIATE'),
+      _commit: this.db.prepare('COMMIT'),
+      _rollback: this.db.prepare('ROLLBACK'),
       getAuthById: this.db.prepare('SELECT * FROM auth WHERE id = :id'),
       getLinkById: this.db.prepare('SELECT * FROM link WHERE id = :id'),
       getLinkByUrl: this.db.prepare('SELECT * FROM link WHERE url = :url'),
@@ -149,7 +144,16 @@ class SQLiteDatabase extends BaseDatabase {
 
   async transaction(dbCtx, fn, ...rest) {
     dbCtx = dbCtx || this.db;
-    return await dbCtx.transaction(async (...args) => await fn(...args))(dbCtx, ...rest);
+    try {
+      this.statement._beginImmediate.run();
+      const result = await fn(dbCtx, ...rest);
+      this.statement._commit.run();
+      return result;
+    } finally {
+      if (this.db.inTransaction) {
+        this.statement._rollback.run();
+      }
+    }
   }
 
   async getAuthById(dbCtx, id) {