forked from askmike/gekko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
executable file
·58 lines (50 loc) · 1.5 KB
/
util.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var config = require('../../core/util.js').getConfig();
var watch = config.watch;
if(watch) {
var settings = {
exchange: watch.exchange,
pair: [watch.currency, watch.asset]
}
}
/**
* Returns true if we use single database where
* all our tables are stored. The default is to store
* every exchange into it's own db.
*
* Set config.postgresql.database to use single db setup
*/
function useSingleDatabase() {
return !!config.postgresql.database;
}
/**
* Postgres has tables in lowercase if you don't
* escape their names. Which we don't and so let's
* just lowercase them.
*/
function useLowerCaseTableNames() {
return !config.postgresql.noLowerCaseTableName;
}
module.exports = {
settings: settings,
// true if we have single db setup (see postrgesql.database config key)
useSingleDatabase: useSingleDatabase,
// returns DB name (depends on single db setup)
database: function () {
return useSingleDatabase() ?
config.postgresql.database :
config.watch.exchange.toLowerCase();
},
// returns table name which can be different if we use
// single or multiple db setup.
table: function (name) {
if (useSingleDatabase()) {
name = watch.exchange + '_' + name;
}
var fullName = [name, settings.pair.join('_')].join('_');
return useLowerCaseTableNames() ? fullName.toLowerCase() : fullName;
},
// postgres schema name. defaults to 'public'
schema: function () {
return config.postgresql.schema ? config.postgresql.schema : 'public';
}
}