feat(dx/desktop): perfect way to override bettersqlite native

This commit is contained in:
Elian Doran
2025-09-02 11:50:53 +03:00
parent 16beeb2e88
commit 7fdea613ff
5 changed files with 19 additions and 10 deletions

View File

@@ -15,6 +15,10 @@ import becca_loader from "../becca/becca_loader.js";
import entity_changes from "./entity_changes.js";
import config from "./config.js";
const dbOpts: Database.Options = {
nativeBinding: process.env.BETTERSQLITE3_NATIVE_PATH || undefined
};
let dbConnection: DatabaseType = buildDatabase();
let statementCache: Record<string, Statement> = {};
@@ -23,15 +27,18 @@ function buildDatabase() {
if (process.env.TRILIUM_INTEGRATION_TEST === "memory") {
return buildIntegrationTestDatabase();
} else if (process.env.TRILIUM_INTEGRATION_TEST === "memory-no-store") {
return new Database(":memory:");
return new Database(":memory:", dbOpts);
}
return new Database(dataDir.DOCUMENT_PATH, { readonly: config.General.readOnly });
return new Database(dataDir.DOCUMENT_PATH, {
...dbOpts,
readonly: config.General.readOnly
});
}
function buildIntegrationTestDatabase(dbPath?: string) {
const dbBuffer = fs.readFileSync(dbPath ?? dataDir.DOCUMENT_PATH);
return new Database(dbBuffer);
return new Database(dbBuffer, dbOpts);
}
function rebuildIntegrationTestDatabase(dbPath?: string) {

View File

@@ -7,7 +7,10 @@ import sql_init from "../services/sql_init.js";
let dbConnection!: Database.Database;
sql_init.dbReady.then(() => {
dbConnection = new Database(dataDir.DOCUMENT_PATH, { readonly: true });
dbConnection = new Database(dataDir.DOCUMENT_PATH, {
readonly: true,
nativeBinding: process.env.BETTERSQLITE3_NATIVE_PATH || undefined
});
[`exit`, `SIGINT`, `SIGUSR1`, `SIGUSR2`, `SIGTERM`].forEach((eventType) => {
process.on(eventType, () => {