返回语句不能在Arangodb中与用户定义的函数一起使用?如何在函数中编写AQl查询?

xjreopfe  于 2022-12-09  发布在  Go
关注(0)|答案(1)|浏览(151)
require("@arangodb/aql/functions").register(
    "MYFUNCTIONS::VERTEX::INDEGREE", 
    function(vertex,edge, node) {
        "use strict"; 
        AQL_Query(
            (return( "for t in Transaction  collect vertex_count=t._from with into n return x"))
        )
    }
);

引发以下异常

JavaScript exception: SyntaxError: Unexpected token 'return'
!require("@arangodb/aql/functions").register("MYFUNCTIONS::VERTEX::INDEGREE", function(vertex,edge, node) {"use strict"; AQL_Query((return( "for t in Transaction  collect vertex_count=t._from with into n return x")))});
!                                                                                                                                   ^^^^^^
stacktrace: SyntaxError: Unexpected token 'return'
wlzqhblo

wlzqhblo1#

使用aql模板字符串处理程序对查询进行assamble处理,类似于下面的内容应该可以帮助您开始:

require("@arangodb/aql/functions").register(
    "MYFUNCTIONS::VERTEX::INDEGREE", 
    function(vertex,edge, node) {
        "use strict";
        let db = require('@arangodb').db;
        let aql = require('@arangodb').aql;
        
        let query = aql`
            for t in Transaction  
              collect vertex_count=t._from with into n 
              return n
        `;
        return db._query(query).toArray();
    }
);

相关问题