forked from 3V2T/bookstore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbconfig.js
31 lines (27 loc) · 807 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
require('dotenv').config()
const { Sequelize } = require('sequelize')
// connect db
const sequelize = new Sequelize(process.env.DB_CONNECTION_STRING, {
timezone: '+07:00',
})
// const sequelize = new Sequelize(process.env.DB_CONNECTION_STRING, {
// host: process.env.DB_HOST,
// dialect: process.env.DB_DIALECT,
// schema: process.env.DB_SCHEMA,
// timezone: '+07:00',
// dialectOptions: {
// searchPath: process.env.DB_SCHEMA,
// },
// logging: process.env.DB_LOGGING === 'true',
// })
const testConnection = async () => {
try {
await sequelize.authenticate()
console.log('Connection has been established successfully.')
} catch (error) {
console.error('Unable to connect to the database:', error)
}
}
sequelize.sync()
testConnection()
module.exports = sequelize