garyvv /
node-sharp
| 1 | const Config = require('../../config/config') |
||
| 2 | const Knex = require('knex') |
||
| 3 | const Logger = require('../handlers/logger') |
||
| 4 | |||
| 5 | //db单例 |
||
| 6 | class DB { |
||
| 7 | constructor() { |
||
| 8 | try { |
||
| 9 | this.readMysql = Knex({ |
||
| 10 | client: 'mysql', |
||
| 11 | connection: { |
||
| 12 | host: Config.read_mysql.host, |
||
| 13 | user: Config.read_mysql.user, |
||
| 14 | password: Config.read_mysql.password, |
||
| 15 | database: Config.read_mysql.database, |
||
| 16 | charset: 'utf8mb4', |
||
| 17 | collation: 'utf8mb4_unicode_ci' |
||
| 18 | }, |
||
| 19 | pool: { min: Config.read_mysql.minConnection, max: Config.read_mysql.maxConnection } |
||
| 20 | }) |
||
| 21 | Logger.getLogger('system').trace('readMysql init') |
||
| 22 | |||
| 23 | this.writeMysql = Knex({ |
||
| 24 | client: 'mysql', |
||
| 25 | connection: { |
||
| 26 | host: Config.write_mysql.host, |
||
| 27 | user: Config.write_mysql.user, |
||
| 28 | password: Config.write_mysql.password, |
||
| 29 | database: Config.write_mysql.database, |
||
| 30 | charset: 'utf8mb4', |
||
| 31 | collation: 'utf8mb4_unicode_ci' |
||
| 32 | }, |
||
| 33 | pool: { min: Config.write_mysql.minConnection, max: Config.write_mysql.maxConnection } |
||
| 34 | }) |
||
| 35 | Logger.getLogger('system').trace('writeMysql init') |
||
| 36 | } catch (e) { |
||
| 37 | console.log(e) |
||
|
0 ignored issues
–
show
Debugging Code
introduced
by
Loading history...
|
|||
| 38 | } |
||
| 39 | } |
||
| 40 | } |
||
| 41 | |||
| 42 | module.exports = new DB() |