这是 sequelize 官方给的 query 操作示例。
// Callee is the model definition. This allows you to easily map a query to a predefined model
sequelize.query('SELECT * FROM projects', { model: Projects }).then(projects => {
// Each record will now be a instance of Project
})
我试着使用以下方式来使用,但报错了,同级的 app.Sequelize.fn 是正常的。由于相关资料较少,本人也是 node 新手,故来求助。
'use strict';
module.exports = app => {
return class UserController extends app.Controller {
async userList() {
const ctx = this.ctx;
const result = await app.Sequelize.query('SELECT * FROM users', { model: ctx.model.User });
console.log(result); // TypeError: app.Sequelize.query is not a function
await ctx.render('front/user.html');
}
};
};
使用app.model.query试试。
@iyuq 试了下,这个方法可以
Most helpful comment
使用
app.model.query试试。