Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

110
Views
Waterline ORM (sails.js) "where or" - effiency

I am using Waterline ORM (sails.js), and the query "where or".

I have a query with a multiple 'or' in the 'where' section, that checks if any of 2 specific fields are equal to a value in an array

and should return that item,

lets say the array is var array = ["Jack", "Kyle","Stan", "Randy"]

and the fields are 'name' and 'nickName' , and the query runs -

where 
 'name' or 'nickName' equals "Jack"
or
'name' or 'nickName' equals "Kyle"
or
'name' or 'nickName' equals "Stan"
or
'name' or 'nickName' equals "Randy"

Now the query runs extremely slow, and I wish to make it faster.

is there a way to make the query faster using sails.js? by the waterline ORM?

7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

await Users.find({ 
  where: { 
    or: [
      { name: ["Jack", "Kyle","Stan", "Randy"] },
      { nickName: ["Jack", "Kyle","Stan", "Randy"] },
    ]
  } 
})

or : modifier to match any of the nested rule sets you specify as an array of query pairs.

{ name: ["Jack", "Kyle","Stan", "Randy"] }

This is more or less equivalent to "IN" queries in SQL

More about Waterline query language

7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs