/* * clippr: a social bookmarking service for the AT Protocol * Copyright (c) 2025 clippr contributors. * SPDX-License-Identifier: AGPL-3.0-only */ import { drizzle } from "drizzle-orm/libsql"; import { Config } from "../config.js"; import Logger from "../logger.js"; const config = Config.getInstance().getConfig(); const dbname = config.database.name; class DatabaseError extends Error { constructor(message: string) { super(message); this.name = "DatabaseError"; } } export class Database { private static instance: Database; private readonly db; private constructor() { try { this.db = drizzle({ connection: { url: `${dbname}` } }); } catch (e: unknown) { if (e instanceof Error) { throw new DatabaseError(e.message); } else throw new DatabaseError("Unknown error"); } } static getInstance(): Database { if (!Database.instance) { try { Database.instance = new Database(); } catch (e) { Logger.error(e); process.exit(1); } } return Database.instance; } getDb() { return this.db; } }