UNPKG

@debito/hippo-lib

Version:

Double-entry accounting library for CouchDB

54 lines (46 loc) 1.23 kB
import CouchDBDriver from './drivers/CouchDBDriver.js'; // Configuration storage let db = null; let databaseName = null; /** * Initialize database configuration * @param {string} username - CouchDB username * @param {string} password - CouchDB password * @param {string} database - Database name */ function initConfig(username, password, database) { const url = 'https://praman.ctrl.qa:443/db'; db = new CouchDBDriver({ url: url, username: username, password: password, activeDatabase: database }); databaseName = database; } /** * Get database driver instance * @returns {CouchDBDriver} Database driver */ function getDB() { if (!db) { throw new Error('Database not initialized. Call hippo-lib.init() first.'); } return db; } /** * Get current database name * @returns {string} Database name */ function getDatabaseName() { if (!databaseName) { throw new Error('Database not initialized. Call hippo-lib.init() first.'); } return databaseName; } export { initConfig, getDB, getDatabaseName }; export default { initConfig, get db() { return getDB(); }, get DATABASE_NAME() { return getDatabaseName(); } };