我有问题设置的findAll查询与限制返回的数据顺序和偏移,我使用的文档中找到示例代码:order: 'group DESC'
但它抛出一个错误说::Sequelize集中返回的数据如何订购
Error: SQLITE_ERROR: near "group": syntax error
这里是完整的功能。
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);
});
在此先感谢。
的SQL'组by'需要通过定义一个聚合函数组。看起来你还没有定义一个。不确定node.js是否具备执行聚合和分组的功能。 –
@EricLeschinski:感谢您的评论。我最近从'mongodb'转到'SQLite',并且对'SQL'很少了解。你能告诉我一个例子吗? – diosney
@EricLeschinski:请注意:'group'是数据库中的一列。也许这是一个保留字? – diosney