Accept db connection string

This commit is contained in:
hgw 2024-02-02 02:45:36 +00:00
parent 191c57757a
commit 1b9057d67d
Signed by: hgw
SSH Key Fingerprint: SHA256:diG7RVYHjd3aDYkZWHYcBJbImu+6zfptuUP+3k/wol4

View File

@ -126,7 +126,21 @@ class SqliteMessageStorage implements SearchableMessageStorage {
this.initDone = new Deferred(); this.initDone = new Deferred();
} }
async _enable() { async _enable(connection_string: string) {
this.database = new sqlite3.Database(connection_string);
try {
await this.run_pragmas(); // must be done outside of a transaction
await this.run_migrations();
} catch (e) {
this.isEnabled = false;
throw Helper.catch_to_error("Migration failed", e);
}
this.isEnabled = true;
}
async enable() {
const logsPath = Config.getUserLogsPath(); const logsPath = Config.getUserLogsPath();
const sqlitePath = path.join(logsPath, `${this.userName}.sqlite3`); const sqlitePath = path.join(logsPath, `${this.userName}.sqlite3`);
@ -136,22 +150,8 @@ class SqliteMessageStorage implements SearchableMessageStorage {
throw Helper.catch_to_error("Unable to create logs directory", e); throw Helper.catch_to_error("Unable to create logs directory", e);
} }
this.isEnabled = true;
this.database = new sqlite3.Database(sqlitePath);
try { try {
await this.run_pragmas(); // must be done outside of a transaction await this._enable(sqlitePath);
await this.run_migrations();
} catch (e) {
this.isEnabled = false;
throw Helper.catch_to_error("Migration failed", e);
}
}
async enable() {
try {
await this._enable();
} finally { } finally {
this.initDone.resolve(); // unblock the instance methods this.initDone.resolve(); // unblock the instance methods
} }