Replies: 2 comments
-
If you want to use regular AQL syntax, you can pass a regular (raw) query string instead of an AQL template strings. Note that you will have to handle the Personally I copy the queries from my JS/TS code as-is and replace the Note that this syntactical difference is imposed by JavaScript, not arangojs, so there's no way to make AQL template strings look like raw AQL query strings. |
Beta Was this translation helpful? Give feedback.
-
If I understood your question correctly, then perhaps this utility function will help: export const aqlQueryToString = (aqlQuery: GeneratedAqlQuery): string => {
const bindVars = aqlQuery.bindVars;
const query = aqlQuery.query.replace(/\n\s*\n\s*\n/g, `\n`);
return Object.keys(bindVars).reduce((acc, key) => {
const value = bindVars[key];
if (key.startsWith(`@`)) {
return acc.replace(`@${key}`, value);
}
return acc.replace(`@${key}`, `"${value}"`);
}, query);
}; const query = aql`
FOR x IN ${collection}
${orgId}
${selector}
${global}
${extraAql}
LIMIT 1
RETURN x
`);
aqlQueryToString(query)
// output:
FOR x IN user
FILTER x.orgId == "organization/35229c47-4d1e-46db-890b-9aedea434ac2"
FILTER x._id == "user/a78fc2a9-e5c4-40ae-bb23-a7213ee7ac4a"
LIMIT 1
RETURN x |
Beta Was this translation helpful? Give feedback.
-
Usually I copy query to/from arangodb web interface for testing. It works with old-style binding. But for aql-templates I have to convert query and it becomes completely unusable.
Maybe there is auto converter for aql-templates? Or other way to debug queries?
Beta Was this translation helpful? Give feedback.
All reactions