I am trying to update an existing postgres query in the Nodejs code base.
Below is the existing query to select based on name
constructor(schema){
this.table = schema.employee_tb;
}
row = await this.table.findOne({ name });
Below is the Postgres query I am trying to translate and update the above code into…
select * from table where name = 'john' and '3467' = ANY(group_number)
I tried
row = await this.table.findOne({ name : 'john' && ANY(group_number): '3467' });
For which it is throwing an error.
Basically, I am trying to have the ANY operator in using the massive library.
NOTE: group_number is character_varying[] which has data like {3467, 3455, 3421}….. the query should return the row which contains the group number in the group_number column.
Please help, Thanks in advance.
2
Answers
This worked!!
If you are looking to
findOne
that has thename
‘john’ AND thegroup_number
‘3467’, you need to update your object syntax.If you are using Sequelize here for the
findOne
method, I would take a look at the docs here where you can add in the ANY operator withOp.any
in your query, but you will need to have thatcharacter_varying[]
ready to pass into the function.