0

这个查询:

FOR clinic IN exameFacil_clinics
                    LET procedures_list = (
                    FOR procedure IN clinic.procedures
                    FILTER LIKE(procedure.name, "%hemo%", true)
                    COLLECT procedures_list = procedure.name
                    RETURN procedures_list
                )
                FILTER LENGTH(procedures_list) > 0
                RETURN{
                        clinic_name: clinic.name,
                        procedures_list: procedures_list}

在 AQL 编辑器的 ArangoDB 的 Web 界面中执行时工作正常并返回预期结果,但是当我尝试在 FOXX 存储库中执行时给我一个错误:

'use strict';
var Foxx = require('org/arangodb/foxx');

module.exports = Foxx.Repository.extend({
  // Add your custom methods here

  //Return all procedures from a clinic, given the clinic id
  getAllProcedures: Foxx.createQuery({
        query: 'FOR clinic IN exameFacil_clinics FILTER clinic._key == @id RETURN clinic.procedures',
        params: ['id']

    }),

  //Make a 'LIKE' query in all procedures from all clinics, given the search string ( procedure name )
  searchProcedure: Foxx.createQuery({
        query: 'FOR clinic IN exameFacil_clinics
                    LET procedures_list = (
                    FOR procedure IN clinic.procedures
                    FILTER LIKE(procedure.name, "%hemo%", true)
                    COLLECT procedures_list = procedure.name
                    RETURN procedures_list
                )
                FILTER LENGTH(procedures_list) > 0
                RETURN{
                        clinic_name: clinic.name,
                        procedures_list: procedures_list}'

    }),

});

错误:

[ArangoError 3103: 调用模块文件失败:c:/Program Files/ArangoDB 2.6.2/var/lib/arangodb-apps/_db/_system/exameFacil/APP/controllers/clinics.js] 在 [object Object].Module .run (C:\Program Files\ArangoDB 2.6.2\bin../share/arangodb/js/common/bootstrap/modules.js:1420:20) 在 ArangoApp.loadAppScript (c:/Program Files/ArangoDB 2.6. 2/share/arangodb/js/server/modules/org/arangodb/foxx/arangoApp.js:452:24) 在 mountController (c:/Program Files/ArangoDB 2.6.2/share/arangodb/js/server/modules/ org/arangodb/foxx/routing.js:661:7) 在 c:/Program Files/ArangoDB 2.6.2/share/arangodb/js/server/modules/org/arangodb/foxx/routing.js:630:9 在Array.forEach (native) at routeApp (c:/Program Files/ArangoDB 2.6.2/share/arangodb/js/server/modules/org/arangodb/foxx/routing.js:629:32) 在 Object.routes (c :/程序文件/ArangoDB 2.6。2/share/arangodb/js/server/modules/org/arangodb/foxx/manager.js:268:10) 在 foxxRouting (c:/Program Files/ArangoDB 2.6.2/share/arangodb/js/server/modules/ org/arangodb/actions.js:1054:74) 在对象处执行 (c:/Program Files/ArangoDB 2.6.2/share/arangodb/js/server/modules/org/arangodb/actions.js:1308:7) .routeRequest (c:/Program Files/ArangoDB 2.6.2/share/arangodb/js/server/modules/org/arangodb/actions.js:1329:3) 在 Function.actions.defineHttp.callback (c:\ \ArangoDB 2.6.2\share\arangodb\js\actions\api-system.js:58:15)在 Function.actions.defineHttp.callback (c:\Program Files\ ArangoDB 2.6.2\share\arangodb\js\actions\api-system.js:58:15)在 Function.actions.defineHttp.callback (c:\Program Files\ ArangoDB 2.6.2\share\arangodb\js\actions\api-system.js:58:15)

有什么建议吗?谢谢

4

1 回答 1

2

错误的原因是示例代码中的 JavaScript 解析错误。JavaScript 不支持 function 中使用的多行字符串searchProcedure。要使查询字符串跨越多行,您必须使用字符串连接或模板字符串(用反引号括起来的字符串,ES6 特性)。

字符串连接示例:

searchProcedure: Foxx.createQuery({
  query: 'FOR clinic IN exameFacil_clinics' + 
         '  LET procedures_list = (' +
         // ... string goes on here 
         'procedures_list: procedures_list}'
}),

使用模板字符串的示例:

searchProcedure: Foxx.createQuery({
  query: `FOR clinic IN exameFacil_clinics
            LET procedures_list = (
          // ... string goes on here 
          procedures_list: procedures_list}`
}),

另一种选择是将查询字符串放在一行中。上述查询使用哪种替代方法取决于可读性和样式偏好。

在处理用户生成的输入时,我建议还使用绑定参数将用户输入与实际查询字符串分开并防止注入。

于 2015-08-04T07:01:08.630 回答