:如何设置返回的数据顺序

我有问题设置返回的数据顺序的限制和偏移量的findAll查询,我使用文档中find的示例代码: order: 'group DESC'但它会抛出一个错误说:

 Error: SQLITE_ERROR: near "group": syntax error 

这是完整的function。

 A_Model.findAll({ offset:req.query.page * req.query.rows - req.query.rows, limit :req.query.rows // TODO: Of course, I put the trailing comma here ;) // TODO: order: 'group DESC' }) .success(function (docs) { response_from_server.records = count; response_from_server.page = req.query.page; response_from_server.total = Math.ceil(count / req.query.rows); response_from_server.rows = []; for (item in docs) { response_from_server.rows.push({ id :docs[item].id, cell:[ docs[item].group, docs[item].description, docs[item].path, docs[item].value ] }); } // Return the gathered data. res.json(response_from_server); }) .error(function (error) { logger.log('error', error); }); 

提前致谢。

您给findAll方法的“order”string在Sequelize中不会被parsing,只能转义以防止SQL注入。 “group”是一个保留的关键字 一些 SQL方言,所以查询无法运行。

为了使其工作,只需将“组”列放入“s”中,如下所示:

 A_Model.findAll({ offset:req.query.page * req.query.rows - req.query.rows, limit :req.query.rows, order: '`group` DESC' })