Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Knex where不';不允许将单个字符串传递到“.where()`_Javascript_Node.js_Sqlite_Typescript_Knex.js - Fatal编程技术网

Javascript Knex where不';不允许将单个字符串传递到“.where()`

Javascript Knex where不';不允许将单个字符串传递到“.where()`,javascript,node.js,sqlite,typescript,knex.js,Javascript,Node.js,Sqlite,Typescript,Knex.js,在Node.js中使用Knex和SQLite编写的程序中,我有以下几行代码: await db.table("books") .innerJoin("items", "items.id", "books.item_id") .with("idx", db.raw(`instr(items.name, ?) asc`, name)) .where("idx > 0") .orderBy("idx") .

在Node.js中使用Knex和SQLite编写的程序中,我有以下几行代码:

await db.table("books")
         .innerJoin("items", "items.id", "books.item_id")
         .with("idx", db.raw(`instr(items.name, ?) asc`, name))
         .where("idx > 0")
         .orderBy("idx")
         .select()
其中,
db
是通过调用
knex(config)
创建的变量。但是,函数
raw(sql)
似乎不起作用,因为它在运行时不断抛出此错误:

类型错误:不允许运算符“未定义” 位于Formatter.operator(I:\git\server\node\u modules\knex\lib\Formatter.js:138:13)

位于QueryCompiler\u SQLite3.whereBasic(I:\git\server\node\u modules\knex\lib\query\compiler.js:525:100)

在QueryCompiler\u SQLite3.where(I:\git\server\node\u modules\knex\lib\query\compiler.js:314:32)

我做错了什么

如果相关的话,我用的是Typescript,正如您在
wait
中看到的,我使用的是ES6。但是,如果我排除
with()
,并且
with()
拒绝接受不是由
raw()
创建的内容,则此查询可以正常执行

编辑:

如果我对此进行测试,它表明问题出在
with()
中,而不是
raw()


给出了预期的输出。

结果表明问题出在
where()
上,直到我更仔细地检查堆栈跟踪时才发现。将
.where(“idx>0”)
替换为
.where(“idx”),“>”,0)
修复了它。

变量
名称的值是多少?@Matt如果有关系,它只是一个类似“hello world”的字符串,只是检查这是否是
未定义的值。
console.log("name: " + name);
console.log("db.raw(name): " + db.raw(`instr(items.name, ?) asc`, name));