如何在knex中添加两个绑定参数? [英] How to add two bind params in knex?

查看:113
本文介绍了如何在knex中添加两个绑定参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从数据库中选择内容,我必须使用2个绑定参数.在使用一个参数的情况下,它起作用,但是在使用两个参数的情况下,我收到此错误在编译RAW查询时检测到未定义的绑定"错误,并在nodejs控制台中显示预期的1个绑定,看到了2个".

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?

有效的代码:

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!

推荐答案

尝试在数组中传递两个变量:

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')

应该可以.

这篇关于如何在knex中添加两个绑定参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆