SequelizeJs:按学期排序

时间:2015-03-11 14:34:49

标签: node.js sqlite orm sql-order-by sequelize.js

我在nodejs中使用sequelizejs作为SQLite。我试着得到像这样的SQL:

 SELECT
  id,
  description,
  created_at,
  postponed,
  done_at
FROM tasks
WHERE done_at IS NULL
ORDER by (id+postponed),postponed,id ASC
LIMIT 1

问题是id+postponed中的OREDR BY一词 我试过这个:

Task.find({
          where: ["done_at is not null"],
          order: [["(id+postponed)", "ASC"], ["postponed", "ASC"], ["id", "ASC"]],
          limit: 1
        }).then(...)

但查询变为:ORDER BY task.(task_id+postponed) ASC, task.postponed ASC, task.task_id ASC

有人知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

我自己找到了解决方案:

Task.find({
    where: ["done_at is not null"],
    order: '(id+postponed),postponed,id ASC',
    limit: 1
}).then(...)

这不完美但对我有用。