3 const common
= require('../common');
4 const DatabaseErrors
= require('./errors');
6 const _fileScope
= common
.fileScope(__filename
);
8 class DatabaseFactory
{
9 constructor(logger
, options
, ...rest
) {
10 const _scope
= _fileScope('constructor');
12 const connectionString
= options
.db
.connectionString
|| '';
13 const protocol
= connectionString
.slice(0, connectionString
.indexOf('://')).toLowerCase();
17 case DatabaseFactory
.Engines
.PostgreSQL:
18 Engine
= require('./postgres');
21 case DatabaseFactory
.Engines
.SQLite:
22 Engine
= require('./sqlite');
26 logger
.error(_scope
, 'unsupported connectionString', { protocol
, options
});
27 throw new DatabaseErrors
.UnsupportedEngine(protocol
);
30 return new Engine(logger
, options
, ...rest
);
33 static get Engines() {
35 PostgreSQL: 'postgresql',
42 module
.exports
= DatabaseFactory
;