UNPKG

@sqb/connect

Version:

Multi-dialect database connection framework written with TypeScript

42 lines (41 loc) 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AdapterRegistry = void 0; class AdapterRegistry { static get size() { return this.adapters.length; } static register(...adapters) { for (const adapter of adapters) { if (!adapter.driver) throw new TypeError('A DatabaseAdapter must contain "driver" property'); this.adapters.push(adapter); } } static forEach(callback, thisArg) { return this.adapters.forEach(callback, thisArg); } static items() { return this.adapters.values(); } static unRegister(...extensions) { this.adapters = extensions.filter(x => !extensions.includes(x)); } static getAll(dialect) { return this.adapters.filter(x => x.dialect === dialect); } static get(index) { return this.adapters[index]; } static findDialect(dialect) { return this.adapters.find(x => x.dialect === dialect); } static findDriver(dialect) { return this.adapters.find(x => x.driver === dialect); } static has(extension) { return !!this.adapters.find(x => x === extension); } } exports.AdapterRegistry = AdapterRegistry; AdapterRegistry.adapters = [];