1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-01-23 23:46:52 +00:00

Add support for Node.js integrated sqlite

Available in Node.js 22.50 - see https://nodejs.org/api/sqlite.html

Given the Node.js release timeline, I think it will be reasonable to switch to the integrated Node.js sqlite as the default, which will avoid all the npm install kerfuffle too.
This commit is contained in:
Jeremy Ruston 2025-01-08 12:47:40 +00:00
parent 739ba3288b
commit 19e341c760
3 changed files with 9 additions and 2 deletions

View File

@ -6,7 +6,7 @@ on:
- tiddlywiki-com
- multi-wiki-support
env:
NODE_VERSION: "22"
NODE_VERSION: "23"
jobs:
test:
runs-on: ubuntu-latest

View File

@ -24,7 +24,7 @@ function SqlEngine(options) {
// Initialise the statement cache
this.statements = Object.create(null); // Hashmap by SQL text of statement objects
// Choose engine
this.engine = options.engine || "better"; // wasm | better
this.engine = options.engine || "node"; // node | wasm | better
// Create the database file directories if needed
if(options.databasePath) {
$tw.utils.createFileDirectories(options.databasePath);
@ -33,6 +33,9 @@ function SqlEngine(options) {
const databasePath = options.databasePath || ":memory:";
let Database;
switch(this.engine) {
case "node":
({ DatabaseSync: Database } = require("node:sqlite"));
break;
case "wasm":
({ Database } = require("node-sqlite3-wasm"));
break;

View File

@ -13,6 +13,10 @@ if($tw.node) {
/*global $tw: false */
"use strict";
describe("SQL tiddler database with node built-in sqlite", function() {
runSqlDatabaseTests("node");
});
describe("SQL tiddler database with node-sqlite3-wasm", function() {
runSqlDatabaseTests("wasm");
});