egg-objection
Install
$ npm i egg-objection --save# 从下面选择一种 $ npm install pg$ npm install sqlite3$ npm install mysql$ npm install mysql2$ npm install mariasql
Usage
// {app_root}/config/plugin.jsexportsobjection = enable: true package: 'egg-objection';
// {app_root}/config/config.default.jsconfigobjection = client: knex: client: 'mysql2' // pg/sqlite3/mysql/mysql2/mariasql connection: host: '127.0.0.1' user: 'root' password: 'password_example' database: 'example' delegate: 'model' // 注入model到app[delegate] baseDir: 'model' // model文件目录 ;
see config/config.default.js for more detail.
see Objection Doc for more doc
Example
在app/model新建model
// app/model/user.js 'use strict'; module { model static { return 'users'; } ; return User;}
在controller里使用
// app/controller/home.js 'use strict'; const Controller = Controller; async { const users = await thisctxmodelUser; thisctxbody = users; } moduleexports = HomeController;