3.2.1 • Published 5 years ago
koa-orm v3.2.1
koa-orm
Installation
npm install koa-ormExample
Single database
const join = require('path').join;
const config = {
name: 'test',
modelPath: join(__dirname, 'models'),
database: 'orm_test',
username: 'root',
password: 'pass',
dialect: 'mysql',
host: '127.0.0.1',
port: 3306,
pool: {
max: 10,
min: 0,
idle: 30000
}
};
const orm = require('koa-orm')(config);
app.use(orm.middleware);
app.use(async function (ctx) {
const raws = await ctx.orm().sql.select().from('table');
// const raws = await ctx.orm('test').sql('table').select();
ctx.body = raws;
});Multiple database
const join = require('path').join;
const configs = [{
name: 'user',
database: 'db_user',
username: 'root',
password: 'pass',
dialect: 'mysql',
host: '127.0.0.1',
port: 3306,
modelPath: join(__dirname, 'models/user')
}, {
name: 'product',
database: 'db_product',
username: 'root',
password: 'pass',
dialect: 'mysql',
host: '127.0.0.1',
port: 3306,
modelPath: join(__dirname, 'models/product')
}];
const orm = require('koa-orm')(configs);
app.use(orm.middleware);
app.use(async function (ctx) {
const { User } = ctx.orm('user');
const { Product } = ctx.orm('product');
const { userId } = ctx.params;
const user = await User.findByPk(userId);
const products = await Product.findAll({
where: { userId }
});
ctx.body = { user, products };
});API
orm(configs)
configs: Multi database config array.
Koa 1 Support
To use koa-orm with koa@1, please use koa-orm 1.x.
npm install koa-orm@1 --saveLicense
MIT
3.2.1
5 years ago
3.2.0
5 years ago
3.1.1
5 years ago
3.1.0
6 years ago
3.0.2
6 years ago
3.0.1
6 years ago
3.0.0
6 years ago
2.3.6
7 years ago
2.3.5
7 years ago
2.3.4
7 years ago
2.3.3
7 years ago
2.3.2
7 years ago
2.3.1
7 years ago
2.3.0
8 years ago
2.2.0
9 years ago
2.1.0
9 years ago
2.0.0
9 years ago
2.0.0-beta.1
9 years ago
1.2.0
9 years ago
1.1.1
9 years ago
1.1.0
10 years ago
1.0.1
10 years ago
1.0.0
10 years ago
0.1.0
10 years ago
0.0.6
10 years ago
0.0.5
10 years ago
0.0.4
10 years ago
0.0.3
10 years ago
0.0.2
10 years ago
0.0.1
10 years ago