-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbConfig.js
52 lines (46 loc) · 978 Bytes
/
dbConfig.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
const Sequelize = require("sequelize");
let dbConfig = {
DB: 'postgres',
name: 'admin',
password: '1234',
host: 'localhost'
}
var sequelize = new Sequelize(
dbConfig.DB, // db name
dbConfig.name, // username
dbConfig.password, // password
{
host: dbConfig.host, // host
dialect: "postgres",
acquireConnectionTimeout: 5000,
pool: {
min: 0,
max: 100,
createTimeoutMillis: 8000,
acquireTimeoutMillis: 8000,
idleTimeoutMillis: 8000,
reapIntervalMillis: 1000,
createRetryIntervalMillis: 100,
propagateCreateError: false
}
// , port: 5433
});
var connectDB = async () => {
try {
console.log("Connect to Database");
await sequelize.authenticate()
.then(() => {
sequelize.sync();
console.log("database connected !");
})
.catch(err => {
console.error("Unable to connect to the database:", err);
});
} catch (error) {
throw error;
}
};
module.exports = {
connectDB: connectDB,
sequelize: sequelize
};