简体   繁体   中英

How to write case insensitive order query in sequelize(SQLite)?

I am trying to order by my data based on an attribute. Here I have a model name Farmer and I am ordering this model by name. The query is like this:

Farmer.findAll({order: [['name', 'ASC']]})

Which is ordering data case sensitively. But I want to order this case insensitively. How can i get it?

You could use sequelize.fn ( http://docs.sequelizejs.com/class/lib/sequelize.js~Sequelize.html#static-method-fn ) to transform your name to lowercase

Farmer.findAll({
  order: [
    [
      Sequelize.fn('lower', Sequelize.col('name')),
      'ASC',
    ],
  ],
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM