2017-11-02 9 views
0

は私がKnexとSQLiteの使用のNode.jsで書かれたプログラムに次の行があります。dbが作成された変数があるKnex()`

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

knex(config)に電話してください。私は間違って何をやっている

TypeError: The operator "undefined" is not permitted at Formatter.operator (I:\git\server\node_modules\knex\lib\formatter.js:138:13)

at QueryCompiler_SQLite3.whereBasic (I:\git\server\node_modules\knex\lib\query\compiler.js:525:100)

at QueryCompiler_SQLite3.where (I:\git\server\node_modules\knex\lib\query\compiler.js:314:32)

:それは、実行時にこのエラーを投げ続けるしかし、機能raw(sql)は、動作するようには思えないのですか?

もし私がTypescriptで書いているのであれば、awaitでわかるように、私はES6を使っています。ただし、with()を除外するとこのクエリは正常に実行され、with()raw()で作成されていないものを受け入れることを拒否します。

編集:私はこれをテストした場合

、それは問題がraw()with()ない中であることを示しています

console.log("name: " + name); 
console.log("db.raw(name): " + db.raw(`instr(items.name, ?) asc`, name)); 

は、期待される出力を提供します。

+0

'name'変数の値は何ですか? – Matt

+0

@Matt重要なのは、 "hello world"のような文字列です – Ibi

+0

それが 'undefined'値であるかどうかを調べるだけです。 – Matt

答えて

0

この問題は、スタックトレースをより詳細に検査するまで表示されなかったwhere()であることが判明しました。 .where("idx > 0").where("idx", ">", 0)に置き換えて修正しました。

関連する問題