ArangoDB是一個(gè)多模型數(shù)據(jù)庫(kù),它使用AQL(ArangoDB查詢語(yǔ)言)作為查詢和操作數(shù)據(jù)的語(yǔ)言。為了簡(jiǎn)化代碼,你可以遵循以下建議:
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;
}
通過(guò)遵循這些建議,你可以簡(jiǎn)化ArangoDB查詢語(yǔ)言代碼,使其更易讀、高效且易于維護(hù)。