3 const common
= require('../common');
4 const DBErrors
= require('./errors');
6 const _fileScope
= common
.fileScope(__filename
);
8 const defaultOptions
= {
12 class DatabaseFactory
{
13 constructor(logger
, options
, ...rest
) {
14 const _scope
= _fileScope
+ ':constructor';
15 options
= Object
.assign({}, defaultOptions
, options
);
16 const protocol
= options
.connectionString
.slice(0, options
.connectionString
.indexOf('://')).toLowerCase();
17 // eslint-disable-next-line sonarjs/no-small-switch
19 case DatabaseFactory
.Engines
.PostgreSQL: {
20 const Postgres
= require('./postgres');
21 return new Postgres(logger
, options
, ...rest
);
24 case DatabaseFactory
.Engines
.SQLite: {
25 const SQLite
= require('./sqlite');
26 return new SQLite(logger
, options
, ...rest
);
30 logger
.error(_scope
, 'unsupported connectionString', { options
});
31 throw new DBErrors
.UnsupportedEngine(protocol
);
35 static get Engines() {
37 PostgreSQL: 'postgresql',
44 module
.exports
= DatabaseFactory
;