WiseLibs / better-sqlite3

The fastest and simplest library for SQLite3 in Node.js.
MIT License
5.26k stars 391 forks source link

Extensions share state #1103

Closed LaurentDhont closed 8 months ago

LaurentDhont commented 8 months ago

The sqlite extension used is the following: https://github.com/mergestat/dblite

It must be something with better-sqlite3 because when I try to replicate this using the sqlite3 cli this does not occur. So somehow better-sqlite3 shares state between connection with the extension... When looking into this at first I thought it had to do with this return code: SQLITE_OK_LOAD_PERMANENTLY (256) but when trying on the cli it didn't share the state...

const Database = require('better-sqlite3-default-extensions-helper')(require('better-sqlite3'));

const dbPath1 = 'path1';
const dbPath2 = 'path2';

const db1 = new Database(dbPath1);

db1.prepare("SELECT dblite_open('mysql', 'mydb', 'username:password@tcp(host:port)/scheme')").get();
db1.close();
const db2 = new Database(dbPath2);

console.log(db2.prepare("SELECT dblite_ping('mydb')").get()); // returns 1, so it found the connection even tho it was created on db1
LaurentDhont commented 8 months ago

I found it out, its because it only shares state when running in the same process.