gpt4 book ai didi

arangodb - 获取 "ArangoError: bind parameter ' 值 1' was not declared in the query (while parsing)"

转载 作者:行者123 更新时间:2023-12-04 22:57:54 26 4
gpt4 key购买 nike

我的 Foxx 应用程序中有这样的代码:

db._query(aqlQuery`
FOR d IN FULLTEXT('api_texts', '${args.attribute}', '${args.search}')
SORT d.${args.sort_by} ${args.sort}
LIMIT ${args.skip}, ${args.limit}
RETURN d
`).toArray()

这似乎是正确的,但由于某种原因它给了我一个错误 bind parameter 'value1' was not declared in the query (while parsing) .

我尝试在 arangosh 中运行它...那里也有同样的错误:
arangosh [ilearn]> db._query({ "query" : "\n        FOR d IN FULLTEXT('api_texts', '@value0', '@value1')\n          SORT d.@value2 @value3\n          LIMIT @value4, @value5\n          RETURN d\n      ", "bindVars" : { "value0" : "title_en", "value1" : "1", "value2" : "created_at", "value3" : "ASC", "value4" : 0, "value5" : 10 } })
JavaScript exception in file '/usr/local/Cellar/arangodb/2.8.6/share/arangodb/js/client/modules/org/arangodb/arangosh.js' at 106,13: ArangoError 1552: bind parameter 'value1' was not declared in the query (while parsing)
! throw error;
! ^
stacktrace: ArangoError: bind parameter 'value1' was not declared in the query (while parsing)
at Object.exports.checkRequestResult (/usr/local/Cellar/arangodb/2.8.6/share/arangodb/js/client/modules/org/arangodb/arangosh.js:104:21)
at ArangoStatement.execute (/usr/local/Cellar/arangodb/2.8.6/share/arangodb/js/client/modules/org/arangodb/arango-statement.js:186:12)
at ArangoDatabase._query (/usr/local/Cellar/arangodb/2.8.6/share/arangodb/js/client/modules/org/arangodb/arango-database.js:814:45)
at <shell command>:1:4

难道我做错了什么?请帮忙。谢谢!

PS: OS X 上的 Arangodb v2.8.6

最佳答案

您的错误是您在绑定(bind)值周围加上引号。绑定(bind)值不得设置在引号中。

由于您使用的是模板字符串,因此绑定(bind)值会自动分配一个名称:valueN .模板字符串引擎将您的查询翻译成如下内容:

db._query(`
FOR d IN FULLTEXT('api_texts', '@value0', '@value1')
SORT d.@value2 @value3
LIMIT @value4, @value5
RETURN d
`, {value0: args.attribute, value1.... }).toArray()

我们最好通过调用模板处理器来检查这一点,而不是将结果直接放入 db._query()。 :
args={
attribute: "theAttribute",
search: "theSearchString",
sort_by: "sortByMe",
skip: 5,
limit: 10
}
aqlQuery`FOR d IN FULLTEXT('api_texts', '${args.attribute}', '${args.search}')
SORT d.${args.sort_by} ${args.sort} LIMIT ${args.skip}, ${args.limit} RETURN d`
{
"query" : "FOR d IN FULLTEXT('api_texts', '@value0', '@value1')
SORT d.@value2 @valu...",
"bindVars" : {
"value0" : "theAttribute",
"value1" : "theSearchString",
"value2" : "sortByMe",
"value3" : undefined,
"value4" : 5,
"value5" : 10
}
}

由于绑定(bind)值不能在字符串中(否则它们被视为字符串),您的查询将不会引用 @value0@value1 ,这就是错误的含义:

绑定(bind)值列表中指定的绑定(bind)值,查询未引用该绑定(bind)值。

更正了 ${...} 周围不带引号的代码:
db._query(aqlQuery`
FOR d IN FULLTEXT('api_texts', ${args.attribute}, ${args.search})
SORT d.${args.sort_by} ${args.sort}
LIMIT ${args.skip}, ${args.limit}
RETURN d
`).toArray()

关于arangodb - 获取 "ArangoError: bind parameter ' 值 1' was not declared in the query (while parsing)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36680832/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com