最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to add two bind params in knex? - Stack Overflow

programmeradmin2浏览0评论

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 piling 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!

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 piling 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!

Share Improve this question asked Jan 28, 2019 at 17:59 Pavel ProdanPavel Prodan 692 silver badges7 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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.

发布评论

评论列表(0)

  1. 暂无评论