Amadou Beye
Amadou Beye

Reputation: 2828

Sequelize: How to order results by CHAR LENGTH?

Is there a way to order my results by the length (characters) of a column in sequelise ?

For example if I search for "lor" I would like to get result below:

results
________________
lor
lorem
lorem ip
lorem ips
lorem ipsum

Any suggestions gratefully received

Upvotes: 0

Views: 2414

Answers (1)

Darshan Mehta
Darshan Mehta

Reputation: 30849

You can use ORDER, e.g.:

order: [
    [sequelize.fn('length', sequelize.col('column_name')), 'DESC']
 ]

Upvotes: 5

Related Questions