mirror of
https://github.com/thelounge/thelounge
synced 2024-11-24 21:13:06 +00:00
sqlite: accept db connection string
This allows us to inject a memory db during testing
This commit is contained in:
parent
60ddf17124
commit
aec8d0b033
1 changed files with 16 additions and 16 deletions
|
@ -116,7 +116,21 @@ class SqliteMessageStorage implements SearchableMessageStorage {
|
|||
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 sqlitePath = path.join(logsPath, `${this.userName}.sqlite3`);
|
||||
|
||||
|
@ -126,22 +140,8 @@ class SqliteMessageStorage implements SearchableMessageStorage {
|
|||
throw Helper.catch_to_error("Unable to create logs directory", e);
|
||||
}
|
||||
|
||||
this.isEnabled = true;
|
||||
|
||||
this.database = new sqlite3.Database(sqlitePath);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
async enable() {
|
||||
try {
|
||||
await this._enable();
|
||||
await this._enable(sqlitePath);
|
||||
} finally {
|
||||
this.initDone.resolve(); // unblock the instance methods
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue