egg-sequelize 中使用 query 报 not a function

Created on 7 Aug 2017  ·  2Comments  ·  Source: eggjs/egg

  • Node Version:8.1.4
  • Egg Version:1.7.0
  • Plugin Name:egg-sequelize
  • Plugin Version:3.1.0
  • Platform:windows 10 x64
  • Mini Showcase Repository:

这是 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');
    }
  };
};
document

Most helpful comment

使用app.model.query试试。

All 2 comments

使用app.model.query试试。

@iyuq 试了下,这个方法可以

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Webjiacheng picture Webjiacheng  ·  3Comments

zhaofinger picture zhaofinger  ·  3Comments

kylezhang picture kylezhang  ·  3Comments

weijiatan456 picture weijiatan456  ·  3Comments

bupafengyu picture bupafengyu  ·  3Comments