-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
47 lines (38 loc) · 1.16 KB
/
db.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
// utf8mb4_unicode_520_ci
const Sequelize = require('sequelize')
const logger = require('./logger')
require('dotenv').config()
let sequelize = null
if (process.env.TESTING) {
sequelize = new Sequelize({
dialect: 'sqlite',
storage: ':memory:',
logging: logger.logdb1, // Only logs first parameter to avoid error
define: {
timestamps: false, // Having as true weirdly causes test errors in Seqelize 5.22+
dateStrings: true
}
})
} else {
const database = process.env.DATABASE
const dbuser = process.env.DBUSER
const dbpass = process.env.DBPASS
sequelize = new Sequelize(database, dbuser, dbpass, {
host: 'localhost',
dialect: 'mysql',
operatorsAliases: '0',
// logging: logger.log, // This causes sequelize error for related objects: Converting circular structure to JSON
logging: logger.logdb1, // Only logs first parameter to avoid above error
define: {
timestamps: true, // true by default so as to add the timestamp attributes (updatedAt, createdAt)
dateStrings: true
},
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
}
})
}
module.exports = sequelize