sunfuze / egg-knex

knex plugin for egg
MIT License
57 stars 15 forks source link

是否支持自主传入连接参数动态创建knex #28

Closed vvizden closed 4 years ago

vvizden commented 4 years ago

是否支持自主传入连接参数动态创建knex

vvizden commented 4 years ago

类似于knex官网:

var knex = require('knex')({
  client: 'mysql',
  connection: {
    host : '127.0.0.1',
    user : 'your_database_user',
    password : 'your_database_password',
    database : 'myapp_test'
  }
});
vvizden commented 4 years ago

抱歉,没仔细看egg api。最后发现,可使用以下代码动态创建

app.knex.createInstance({
  client: 'mysql',
  connection: {
    host : '127.0.0.1',
    user : 'your_database_user',
    password : 'your_database_password',
    database : 'myapp_test'
  }
})