UNPKG

@sentzunhat/zacatl

Version:

A modular, high-performance TypeScript microservice framework for Node.js, featuring layered architecture, dependency injection, and robust validation for building scalable APIs and distributed systems.

43 lines 1.38 kB
import { CustomError } from '../../../../../error/index.js'; export class SqliteAdapter { db; static _moduleCached = null; static async loadModule() { if (!this._moduleCached) { this._moduleCached = import('node:sqlite'); } return this._moduleCached; } async connect(_serviceName, config) { const { connectionString } = config; if (connectionString == null || connectionString.length === 0) { throw new CustomError({ message: 'SQLite connection string (file path) is required', code: 500, reason: 'connectionString must be a valid file path or :memory:', }); } try { const mod = await SqliteAdapter.loadModule(); this.db = new mod.DatabaseSync(connectionString, { defensive: true }); } catch (error) { throw new CustomError({ message: `Failed to open SQLite database at "${connectionString}"`, code: 500, reason: 'SQLite open failed', error: error, }); } } async disconnect() { if (this.db !== undefined) { this.db.close(); this.db = undefined; } } getDatabase() { return this.db; } } //# sourceMappingURL=sqlite.js.map