Sequelize数据库中文排序

2023年1月15日09:26:44

首先要排序的字段要是索引,然后一下是Sequelize的代码

const sequelize = this.ctx.model;
const datas = await this.ctx.model.Folder.findAll({
  where: { pid: 81 },
  order: [[ sequelize.literal('convert(name using gbk)'), 'DESC' ]]
});

按照name字段来进行排序,DESC表示逆序

const sequelize = this.ctx.model;
const datas = await this.ctx.model.Folder.findAll({
  where: { pid: 190 },
  order: sequelize.literal('convert(name using gbk)')
});

这个的话默认是ASC排序的

  • 作者:魔笛Love
  • 原文链接:https://blog.csdn.net/clearlxj/article/details/109215353
    更新时间:2023年1月15日09:26:44 ,共 363 字。