sunfuze / egg-knex

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

是不是不支持Typescript? #19

Closed codeWinson closed 5 years ago

codeWinson commented 6 years ago

配置部分: ${app_root}/config/plugin.ts: import { EggPlugin } from 'egg'; const plugin: EggPlugin = { knex: { enable: true, package: 'egg-knex' } }; export default plugin; ${app_root}/config/config.${env}.ts: import { DefaultConfig } from './config.default'; export default () => { const config: DefaultConfig = {}; config.knex = { client: { dialect: 'mysql', connection: { host: '127.0.0.1', port: '3306', user: 'root', password: '111111', database: 'life' }, pool: { min: 0, max: 5 }, acquireConnectionTimeout: 30000, }, app: true, agent: true, } return config; }; 结果: image 在Application对象上获取不到knex?

sunfuze commented 6 years ago

目前不支持,后面加上index.d.ts。目前你可以在extend/context.ts,加上

{
  get knex() {
    return (this.app as any).knex
  }
}

通过 ctx 去获取knex 实例。不过这种方式还是会有一些问题。