forked from appirio-tech/lc1-challenge-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datasource.js
42 lines (38 loc) · 1009 Bytes
/
datasource.js
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
36
37
38
39
40
41
42
/**
* Copyright (c) 2014 TopCoder, Inc. All rights reserved.
*/
'use strict';
var datasource = {};
var serenityDatasource = require('serenity-datasource');
/**
* This function will initializes datasource with all the models present in models directory
* @param {Object} config Global configuration object
*/
datasource.init = function(config) {
if (!this.dbInstance) {
// If pgURLWercker exists then use that instead of pgurl
var dbConfig;
if (config.has('datasource.pgURLWercker')) {
dbConfig = {
datasource: {
modelsDirectory: config.get('datasource.modelsDirectory'),
pgURL: config.get('datasource.pgURLWercker')
}
};
} else {
dbConfig = config;
}
this.dbInstance = new serenityDatasource(dbConfig);
}
};
/**
* Return the initialized datasource.
* @return {Object} Datasource Object
*/
datasource.getDataSource = function() {
return this.dbInstance;
};
/**
* Exporting module
*/
module.exports = datasource;