From 2eff666f7b90ab0251a099d31495e72b9ae1f4ea Mon Sep 17 00:00:00 2001 From: Ran Guin Date: Wed, 16 Jun 2021 22:16:58 -0700 Subject: use knexfile for db connection settings --- db/index.js | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/db/index.js b/db/index.js index e9a6052f..e612987b 100644 --- a/db/index.js +++ b/db/index.js @@ -1,26 +1,18 @@ const Sequelize = require("sequelize"); -const conf = config.db; -const debug = require('debug')('test') +const debug = require('debug')('debug'); -debug('DB connection: ', conf.host + ' : ' + conf.database + ' : ' + conf.user) +const dbOptions = require('./../config/knexfile.js')[process.env.NODE_ENV || "development"] -db = new Sequelize(conf.database, conf.user, conf.password, { - host: conf.host, - dialect: conf.dialect, +db = new Sequelize(dbOptions.connection.database, dbOptions.connection.user, dbOptions.connection.password, { + host: dbOptions.connection.host, + dialect: "mariadb", logging: false, - dialectOptions: conf.dialectOptions -}); - -debug('knex conf: ' + JSON.stringify(conf)) -knex = require('knex')({ - client: 'mysql2', - connection: { - user: conf.user, - password: conf.password, - database: conf.database, - host: conf.host - } -}) + dialectOptions: { "multipleStatements": true, "timezone": "Etc/GMT+7" } +}); + +debug('knex dbOptions: ' + JSON.stringify(dbOptions)) + +knex = require('knex')(dbOptions) require("./models/accounts.js"); require("./models/codes.js"); -- cgit v1.2.3