all files / lib/ index.js

45.45% Statements 5/11
33.33% Branches 2/6
100% Functions 1/1
45.45% Lines 5/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35                                                           
/**
 * Configuration is dodo-objection configuration.
 *
 * TODO: Actually... dodo-objection uses configration of this module...
 *
 * @param config Dodo-objection configuration.
 * @return {DatabaseManager}
 */
module.exports = {
  databaseManagerFactory: function databaseManagerFactory(config) {
 
    // Prevent people from invoking this as a constructor.
    Iif (this instanceof databaseManagerFactory) {
      throw new Error('this is not a constructor');
    }
 
    switch (config.knex.client) {
      case 'postgres': {
        var PostgresDatabaseManager = require('./PostgresDatabaseManager').default;
        return new PostgresDatabaseManager(config);
      }
      case 'mysql': {
        var MySqlDatabaseManager = require('./MySqlDatabaseManager').default;
        return new MySqlDatabaseManager(config);
      }
      case 'sqlite': {
        var SqliteDatabaseManager = require('./SqliteDatabaseManager').default;
        return new SqliteDatabaseManager(config);
      }
      default:
        throw new Error(config.knex.client + ' is not supported. Supported clients currently: postgres, mysql and sqlite');
    }
  }
};