2020-09-17 17:58:12 +02:00
|
|
|
'use strict';
|
|
|
|
import { MySQLClient } from './clients/MySQLClient';
|
2021-03-16 18:42:03 +01:00
|
|
|
import { PostgreSQLClient } from './clients/PostgreSQLClient';
|
2020-09-17 17:58:12 +02:00
|
|
|
|
|
|
|
export class ClientsFactory {
|
|
|
|
/**
|
|
|
|
* Returns a database connection based on received args.
|
|
|
|
*
|
|
|
|
* @param {Object} args
|
|
|
|
* @param {String} args.client
|
|
|
|
* @param {Object} args.params
|
|
|
|
* @param {String} args.params.host
|
|
|
|
* @param {Number} args.params.port
|
|
|
|
* @param {String} args.params.password
|
|
|
|
* @param {Number=} args.poolSize
|
|
|
|
* @returns Database Connection
|
|
|
|
* @memberof ClientsFactory
|
|
|
|
*/
|
|
|
|
static getConnection (args) {
|
|
|
|
switch (args.client) {
|
|
|
|
case 'mysql':
|
|
|
|
case 'maria':
|
|
|
|
return new MySQLClient(args);
|
2021-03-16 18:42:03 +01:00
|
|
|
case 'pg':
|
|
|
|
return new PostgreSQLClient(args);
|
2020-09-17 17:58:12 +02:00
|
|
|
default:
|
2021-03-16 18:42:03 +01:00
|
|
|
throw new Error(`Unknown database client: ${args.client}`);
|
2020-09-17 17:58:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|