From a7e753b36cbc6c4b049dfad3d7af4d8df5f3cd92 Mon Sep 17 00:00:00 2001 From: SamTV12345 <40429738+SamTV12345@users.noreply.github.com> Date: Mon, 9 Sep 2024 08:02:17 +0200 Subject: [PATCH] Fixed v4 ueberdb (#747) * Fixed v4 ueberdb * Fixed module not found --------- Co-authored-by: SamTV12345 --- databases/rusty_db.ts | 14 +++++++++++--- databases/sqlite_db.ts | 20 +++++++++++--------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/databases/rusty_db.ts b/databases/rusty_db.ts index 1d2c2533..56a3dcf9 100644 --- a/databases/rusty_db.ts +++ b/databases/rusty_db.ts @@ -1,8 +1,7 @@ import AbstractDatabase from "../lib/AbstractDatabase"; -import {KeyValueDB} from 'rusty-store-kv' export default class Rusty_db extends AbstractDatabase { - db: KeyValueDB |null| undefined + db: any |null| undefined constructor(settings: {filename: string}) { super(settings); @@ -34,7 +33,16 @@ export default class Rusty_db extends AbstractDatabase { } async init() { - this.db = new KeyValueDB(this.settings.filename!); + let RUSTY_DB + try { + RUSTY_DB = await import('rusty-store-kv'); + } catch (err) { + throw new Error( + 'rusty-store-kv not found. It was removed from ueberdb\'s dependencies because it requires ' + + 'compilation which fails on several systems. If you still want to use rusty store kv, run ' + + '"pnpm install rusty-store-kv" in your etherpad-lite ./src directory.'); + } + this.db = new RUSTY_DB.KeyValueDB(this.settings.filename!); } close() { diff --git a/databases/sqlite_db.ts b/databases/sqlite_db.ts index 95261990..5b25ab8e 100644 --- a/databases/sqlite_db.ts +++ b/databases/sqlite_db.ts @@ -1,7 +1,6 @@ 'use strict'; import {BulkObject} from "./cassandra_db"; import AbstractDatabase, {Settings} from "../lib/AbstractDatabase"; -import {SQLite} from 'rusty-store-kv' /** * 2011 Peter 'Pita' Martischka @@ -19,14 +18,8 @@ import {SQLite} from 'rusty-store-kv' * limitations under the License. */ -const escape = (val:string) => `'${val.replace(/'/g, "''")}'`; - -type RequestVal = { - value: string; -} - export default class SQLiteDB extends AbstractDatabase { - public db: SQLite|null; + public db: any|null; constructor(settings:Settings) { super(settings); this.db = null; @@ -50,7 +43,16 @@ export default class SQLiteDB extends AbstractDatabase { } init(callback: Function) { - this.db = new SQLite(this.settings.filename as string) + let SQLITEDB + try { + SQLITEDB = require('rusty-store-kv'); + } catch (err) { + throw new Error( + 'rusty-store-kv not found. It was removed from ueberdb\'s dependencies because it requires ' + + 'compilation which fails on several systems. If you still want to use sqlite, run ' + + '"pnpm install rusty-store-kv" in your etherpad-lite ./src directory.'); + } + this.db = new SQLITEDB.SQLite(this.settings.filename as string) callback(); }