4 ms·
(full disclosure: I work for ArangoDB but this is my own personal opinion) Coming from a JS background AQL is actually pretty easy to learn. Personally the onl
by pluma 8y ago
(full disclosure: I work for ArangoDB but this is my own personal opinion)
Coming from a JS background AQL is actually pretty easy to learn. Personally the only thing that keeps tripping me up is that AQL doesn't have a triple-equals and JS has trained me to avoid double-equals in comparisons.
This is how you fetch every user in a collection:
FOR user IN users RETURN user
This is how you fetch every admin:
FOR user IN users FILTER user.role == "admin" RETURN user
This is how you fetch their email addresses:
FOR user IN users FILTER user.role == "admin" RETURN user.email
Compare this to the equivalent in SQL:
SELECT email FROM users WHERE role == "admin"
The AQL example is IMO easy to read if you know JS or any similar language. AQL even has object and array literals. There are a few idiosyncrasies but you can get very far without needing to invest time to "properly" learn the language. The naive approach usually results in pretty good performance out of the box.
I'd say the mental overhead of switching into AQL and out doesn't quite compare to that of e.g. SQL or even MongoDB queries but you are of course correct that there is some overhead nevertheless. That said, there are community-maintained ODMs for ArangoDB if you don't want to touch another language to write the queries by hand.
I would strongly recommend giving AQL a try though. When I started using ArangoDB (before becoming a contributor) I was hesitant as well but what quickly won me over was that I was able to read most AQL queries without having to learn an entirely new language.
- z3t4 8y ago> This is how you fetch every user in a collection: await db.users This is how you fetch every admin: await db.users.filter( user => user.role == "admin" ) This is how you fetch their email addresses: await db.users.filter( user => user.role == "admin ).map( user => user.email ) I think it can be done using JavaScript Proxy. Here's an update query: user.email = "updated@email.ltd"