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.

36 lines 1.19 kB
import { CustomError } from '../../../../error/index.js'; export class SqliteAdapter { db; 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 { DatabaseSync } = await import('node:sqlite'); this.db = new 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-adapter.js.map