Fluent PHP query builder for ArangoDB’s Query Language (AQL).
(badges)
Using a query builder mainly makes the life of a programmer much easier. You can write cleaner code and be quicker at it. Which of course comes at the cost of application speed.
If you need bleeding edge speed you will need to write your own queries.
The use of a query builder has both pros and cons. It is up to you to decide what you need.
Cons:
- Sacrificing speed
- You still need to understand ArangoDB, AQL and the 'schema' of your database.
- Slight variations between the query builder API and the raw AQL output which may be confusing
Pros
- Programmatically compose queries (e.g. search facets).
- Easy query decomposition
- Dry up your code.
- Reduce AQL syntax bugs
- Flexible expression input
- IDE intellisense.
FluentAQL | ArangoDB | PHP |
---|---|---|
0.x | 3.x * | ^7.2 |
- ArangoDB regularly adds AQL functions and clauses in minor versions. So be sure to check the AQL documentation for the availability of specific features.
The easiest way to install FluentAQL is through composer:
composer require laravel-freelancer-nl/fluentaql
First fire up a new query builder then fluently add AQL clauses on top.
use LaravelFreelancerNL\FluentAQL\QueryBuilder;
...
$qb = new QueryBuilder();
For Example:
$qb->for('i', '1..100')->filter('i', '<', 50)->limit(10)->sort('i', 'desc')->return('i');
$qb->get();
The query builder now contains the query, binds and collections (*) for you to send to ArangoDB through a client.
$query = $qb->query;
$binds = $qb->binds;
$collections = $qb->collections;
- Collections must be passed to ArangoDB in order to prevent deadlocks in certain cluster operations and transactions.
The generated AQL for this query is:
FOR i IN 1..100 FILTER i < 50 LIMIT 10 SORT i DESC RETURN i
See the following pages on details for the API
- Query clauses: how to search, select, sort and limit data
- Statement clauses: data manipulation & variable declaration
- Graph clauses: graph traversals
- Functions: a list of all supported AQL functions
- Subqueries: how to create subqueries, joins etc.
No matter what, never trust user input and always bind it.
$qb->bind('your data')
Binds are registered in order and given an id. If you want to specify the bind name yourself you can add it:
$qb->bind('your data', 'your-bind-id')