How to add two bind params in knex?

妖精的绣舞 提交于 2021-01-05 10:58:26

问题


I'm traying to select something from database and I have to use 2 bind params. With one param it works but with two i get this error "Undefined binding(s) detected when compiling RAW query" error and "Expected 1 bindings, saw 2" in nodejs console.

How to use 2nd bind param?

Code that works:

knex.with('with_alias', knex.raw('select * from "lyrics" where "for_id" = "1" and "var" = ?', var)).select('*').from('with_alias')

I also tried but it didn't worked

knex.with('with_alias', knex.raw('select * from "lyrics" where "for_id" = ? and "var" = ?', var1, var2)).select('*').from('with_alias')

Thanks for help and sorry for bad english!


回答1:


Try to pass two variables in an array:

knex.with('with_alias', knex.raw('select * from "lyrics" where "for_id" = ? and "var" = ?', [var1, var2])).select('*').from('with_alias')

It should work.



来源:https://stackoverflow.com/questions/54407751/how-to-add-two-bind-params-in-knex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!