How to use FIND_IN_SET to continue using mysql DB

How to use FIND_IN_SET in continuation of ORM or any equivalent in sequelize.

+6
source share
1 answer

You need to return to the raw request . Most ORM systems do not cope well with MySQL functions.

As an example for a where query:

// This is *NOT* the best way to use FIND_IN_SET
sequelize.query("SELECT * FROM `users` WHERE FIND_IN_SET(username, 'foo,bar,baz') < 3", { type: sequelize.QueryTypes.SELECT})
  .then(users => {
      // only users with the name "foo" or "bar"
  })


// This is better, I guess.
sequelize.query("SELECT FIND_IN_SET(username, 'foo,bar,baz') as `idx`, id FROM `users`", { type: sequelize.QueryTypes.SELECT})
  .then(value => {
      console.log(value.id + ' has an idx of ' + value.idx);
  })
0
source

Source: https://habr.com/ru/post/1016652/


All Articles