我有問題設置的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