lambdaorm-base
Version:
38 lines • 1.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DataSourceConfigService = void 0;
const domain_1 = require("../../../domain");
class DataSourceConfigService {
constructor() {
this.sources = [];
}
load(value) {
if (value && value.name) {
const index = this.sources.findIndex(p => p.name === value.name);
if (index === -1) {
this.sources.push(value);
}
else {
this.sources[index] = value;
}
}
}
get(name) {
const _name = name === undefined ? this.default : name;
if (_name === undefined) {
if (this.sources.length === 1) {
return this.sources[0];
}
else {
throw new domain_1.SchemaError('the name of the source is required');
}
}
const db = this.sources.find(p => p.name === _name);
if (db === undefined) {
throw new domain_1.SchemaError(`default source: ${_name} not found`);
}
return db;
}
}
exports.DataSourceConfigService = DataSourceConfigService;
//# sourceMappingURL=dataSourceConfigService.js.map