Help building queries based on multiple conditions from an array of objects

Hello, I'm having trouble formulating a query that will match rows to multiple conditions at the same time.

Suppose I have an array of objects like :

const arr = [ 
    { param1 : "val1", param2 : "val2" }, 
    { param2 : "val3", param2 : "val4" }
  ]


and a Table1 with :

col1 : VarChar
col2 : VarChar


where param1 should match up with col1, and param2 should match with col2.


In this example, how can I query Table1 so that I only retrieve rows where (col1 == "val1" && col2 == "val2") or (col1 == "val3" && col2 == "val4") ?

If I extract all the values of param1 and param2, and use them each in an inArray, like :

const param1s = arr.map(x => x.param1)
const param2s = arr.map(x => x.param2)

select().from(table1).where(and(inArray(table1.col1, param1s), inArray(table1.col2, param2s)))



I run the risk of also returning values such as

col1 == "val1"
col2 == "val4"

and

col1 == "val3"
col2 == "val2"


which were not in the original array.


Is there a way to do this?

Thank you
Was this page helpful?