我已经对 arangodb 代码库中的 .js 文件进行了更改,并进行了制作clean && make
并重新启动了 arangod,但似乎没有收到更改。如何确保更改已激活?
更改后的文件是:js/server/modules/org/arangodb/foxx/query.js
让我想到这个想法的文档章节是https://docs.arangodb.com/Foxx/FoxxRepository.html#defining_custom_queries,顺便说一句,它没有显示如何将参数传递给查询,它引用了一个关于 Foxx 的章节查询'我找不到。
最终,目标是不仅将参数传递给查询,还传递给调用的转换函数。差异是
diff --git a/js/server/modules/org/arangodb/foxx/query.js b/js/server/modules/org/arangodb/foxx/query.js
index 49e320c..ac37f34 100644
--- a/js/server/modules/org/arangodb/foxx/query.js
+++ b/js/server/modules/org/arangodb/foxx/query.js
@@ -61,7 +61,7 @@ exports.createQuery = function createQuery (cfg) {
throw new Error('Expected transform to be a function.');
}
- return function query(vars) {
+ return function query(vars, trArgs) {
vars = _.extend({}, defaults, vars);
if (context) {
_.each(vars, function (value, key) {
@@ -76,6 +76,6 @@ exports.createQuery = function createQuery (cfg) {
return new Model(data);
});
}
- return transform ? transform(result) : result;
+ return transform ? transform(result, trArgs:) : result;
};
-};
\ No newline at end of file
+};
存储库将如下所示:
(function () {
"use strict";
var Foxx = require("org/arangodb/foxx");
var Pingers = Foxx.Repository.extend({
ping: Foxx.createQuery({
query: "FOR p IN pingers FILTER p._key == @id return p",
transform: function(items, args) {
var lang = args.lang;
for (var i = 0; i < items.length; i++) {
var item = items[i];
item.name = item.name[lang];
item.description = item.description[lang];
}
return items;
}
}),
exports.Repository = Pingers;
}());
和控制器:
ctrl.get("/ping", function(req, res) {
var id = req.param('id');
var lang = req.param('lang');
res.json(pingers.ping({id: id}, {lang: lang}));
});