-
Notifications
You must be signed in to change notification settings - Fork 0
/
sequelize.js
45 lines (43 loc) · 972 Bytes
/
sequelize.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
const fs = require('fs');
const Sequelize = require('sequelize');
var env = "dev";
const config = require('./config.json')[env];
const sequelize = new Sequelize(
config.database,
config.user,
config.password,
{
dialect: config.dialect,
port: config.port,
host: config.host,
logging: console.log,
define: {
timestamps: false
},
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
}
}
);
sequelize
.authenticate()
.then(function(err) {
console.log('Connection has been established successfully.');
runSqlScript('sql/migration.sql');
})
.catch(function (err) {
console.log('Unable to connect to the database:', err);
});
function runSqlScript(path) {
fs.readFile(path, 'utf-8', function(err, res){
if (err) {
console.log(err);
return;
}
console.log(res);
sequelize.query(res);
});
}