Similar to what I did. I just created a sub package then exported the libsql client, and then overrode the bettersqlite3 package with my local one, also gives local read replica support which I don’t believe is in the @libsql/sqlite3 package.
// ./sqlite3-proxy/index.js
const Database = require("libsql");
module.exports = function (path) {
const ops = {
syncUrl: process.env.TURSO_DB,
authToken: process.env.TURSO_TOKEN,
};
const db = new Database(path, ops);
db.sync();
return db;
};
// ./squite3-proxy/package.json
{
"name": "better-sqlite3",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"libsql": "^0.4.0-pre.10"
}
}
// package.json
{
...
"better-sqlite3": "./sqlite3-proxy/",
...
}