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.

70 lines 2.36 kB
export const createNodeSqliteAdapter = (config) => { class LazyNodeSqliteAdapter { cfg; _inner = null; _loading = null; constructor(cfg) { this.cfg = cfg; void this.ensureLoaded(); } async ensureLoaded() { if (this._inner != null) return; if (this._loading != null) { await this._loading; return; } this._loading = (async () => { try { const mod = await import('./adapter.js'); this._inner = new mod.NodeSqliteAdapter(this.cfg); } catch (err) { const e = err instanceof Error ? err : new Error(String(err)); throw new Error(`Failed to load node:sqlite adapter. Ensure 'node:sqlite' is available (Node.js 24+). Original error: ${e.message}`); } })(); await this._loading; } get inner() { if (this._inner == null) { throw new Error('NodeSqliteAdapter is not yet loaded. Await any async repository method (findById, create, etc.) before accessing the adapter directly.'); } return this._inner; } get model() { return this.cfg.database; } toLean(input) { if (this._inner == null) return null; return this._inner.toLean(input); } async findById(id) { await this.ensureLoaded(); return this.inner.findById(id); } async findMany(filter) { await this.ensureLoaded(); return this.inner.findMany(filter); } async create(entity) { await this.ensureLoaded(); return this.inner.create(entity); } async update(id, update) { await this.ensureLoaded(); return this.inner.update(id, update); } async delete(id) { await this.ensureLoaded(); return this.inner.delete(id); } async exists(id) { await this.ensureLoaded(); return this.inner.exists(id); } } return new LazyNodeSqliteAdapter(config); }; //# sourceMappingURL=index.js.map