ArangoDB是一个多模型数据库,它使用AQL(ArangoDB查询语言)作为查询和操作数据的语言。为了简化代码,你可以遵循以下建议:
const name = "John";
const query = `FOR user IN users FILTER user.name == @name RETURN user`;
db.query(query, { name: name });
const query = `FOR document IN myCollection COLLECT value = SUM(document.value) RETURN { total: value }`;
db.query(query);
const transaction = `
FOR user IN users
UPDATE { name: user.name, age: user.age + 1 } IN users
`;
db.executeTransaction(
{
write: ["users"],
},
transaction
);
const query = `
FOR v, e IN 1..1 OUTBOUND "users/myUser" GRAPH "myGraph"
RETURN v, e
`;
db.query(query);
CREATE PROCEDURE updateUserAge() {
LET user = DOCUMENT("users/myUser");
UPDATE user WITH { age: user.age + 1 } IN users;
RETURN user;
}
通过遵循这些建议,你可以简化ArangoDB查询语言代码,使其更易读、高效且易于维护。