1.0.0 • Published 5 years ago
koa-middleware-orm v1.0.0
koa-middleware-orm
Install
npm i koa-middleware-orm
# or
yarn add koa-middleware-orm
How to use
// user.js
const Sequelize = require('sequelize')
module.exports = function (sequelize) {
const model = sequelize.define('user', {
id: {
field: 'id',
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
name: {
field: 'name',
type: Sequelize.STRING
}
}, { freezeTableName: true, timestamps: false })
return { name: 'user', model }
}
// app.js
const Koa = require('koa')
const orm = require('koa-middleware-orm')
const app = new Koa()
app.use(orm({
host: 'xxx',
db: 'test',
account: 'xxx',
password: 'xxx'
}, ['./user.js']))
app.use(async ctx => {
ctx.body = await ctx.models.user.findAll()
})
app.listen(3000)
LICENSE
1.0.0
5 years ago