Skip to content

Commit

Permalink
First exposure (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
LaravelFreelancerNL authored Oct 12, 2019
1 parent 4cc27e2 commit 80924b4
Show file tree
Hide file tree
Showing 81 changed files with 3,989 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.idea
composer.phar
composer.lock
phpunit.phar
/vendor
.cache
*.cache*
46 changes: 46 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude('tests/Fixtures')
->in(__DIR__)
->append([__DIR__.'/php-cs-fixer'])
;

$config = PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'psr0' => false,
'@PSR2' => true,
'blank_line_after_namespace' => true,
'braces' => true,
'class_definition' => true,
'elseif' => true,
'function_declaration' => true,
'indentation_type' => true,
'line_ending' => true,
'lowercase_constants' => true,
'lowercase_keywords' => true,
'method_argument_space' => [
'ensure_fully_multiline' => true, ],
'no_break_comment' => true,
'no_closing_tag' => true,
'no_spaces_after_function_name' => true,
'no_spaces_inside_parenthesis' => true,
'no_trailing_whitespace' => true,
'no_trailing_whitespace_in_comment' => true,
'single_blank_line_at_eof' => true,
'single_class_element_per_statement' => [
'elements' => ['property'],
],
'single_import_per_statement' => true,
'single_line_after_imports' => true,
'switch_case_semicolon_to_colon' => true,
'switch_case_space' => true,
'visibility_required' => true,
'encoding' => true,
'full_opening_tag' => true,
])
->setFinder($finder)
;

return $config;
10 changes: 10 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
preset: laravel
risky: true
finder:
exclude:
- modules
- node_modules
- storage
- vendor
name: "*.php"
not-name: "*.blade.php"
37 changes: 37 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
language: php

sudo: required

services:
- docker

php:
- 7.1
- 7.2
- 7.3

# Note: The ArangoDB version includes the colon (:), that way we can test pre-releases (i.e. '-preview:3.4.0-rc.4a').
env:
- ARANGODB_VERSION=":3.5.0"

addons:
hosts:
- arangodb

cache:
directories:
- $HOME/.composer/cache
- $HOME/.local

# Pull in ArangoDB first as it needs some time before you can connect after it starts.
# In the mean time Composer can do its thing.
before_script:
- docker pull arangodb/arangodb${ARANGODB_VERSION}
- docker run -d -e ARANGO_NO_AUTH=1 -p 8529:8529 arangodb/arangodb${ARANGODB_VERSION}
- travis_retry composer self-update
- travis_retry composer install --prefer-source --no-interaction
- composer require --dev "orchestra/testbench:${ORCHESTRA_VERSION}" --no-update;
- composer update

script:
- ./vendor/bin/phpunit
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2019 Laravel Freelancer NL

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,38 @@
# aql-query-builder
ArangoDB AQL Query Builder
# FluentAQL

PHP query builder for the [ArangoDB](https://www.arangodb.com) Query Language ([AQL](https://www.arangodb.com/docs/stable/aql/)).

> Version 0.1.x: DO NOT USE IN PRODUCTION YET
## Installation
You may use composer to install FluentAQL:

``` composer require laravel-freelancer-nl/fluentaql ```

### Version compatibility
| FluentAQL | ArangoDB | PHP |
| :------------------ | :---------------- | :---------------- |
| 0.x.x | 3.5.x | 7.2 |

You can use FluentAQL with older versions of ArangoDB, but specific AQL features won't work depending on the version
you're using. The [official AQL documentation](https://www.arangodb.com/docs/stable/aql/) sometimes provides information on
supported versions for clauses, functions and expressions.

## Usage
The Query Builder (QB) has fluent API where you create a new QueryBuilder object and chain AQL statements to create a query.

### Facade
For ease of use you can use the AQB facade to quickly generate a static version of the QB. In the documentation we
solely use the facade, however feel free to just instantiate the QB normally.

```AQB::for('i', '1..100')->return('i')```

### Getting the query, bindings and collection list
the ``get()`` method returns an array with the query, the bindings and a list of used collections.
```AQB::for('i', '1..100')->return('i')->get()```

### Query execution
FluentAQL is solely a query builder so does not include any methods for execution.

You can execute queries with an [ArangoDB PHP driver](https://github.com/arangodb/arangodb-php).
Create a statement and feed it the returned data, then execute the statement.
49 changes: 49 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "laravel-freelancer-nl/aql-query-builder",
"description": "PHP AQL Query Builder",
"keywords": [
"fluentaql",
"arangodb",
"multi-model database",
"document database",
"graph database",
"aql",
"aql query",
"query builder"
],
"license": "MIT",
"authors": [
{
"name": "Laravel Freelancer",
"email": "[email protected]"
}
],
"require": {
"php": ">=7.2",
"ext-json": "*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16@dev",
"localheinz/composer-normalize": "^2.0@dev",
"mockery/mockery": "^1.2",
"nikic/php-parser": "^4.2@dev",
"phpmd/phpmd": "dev-master",
"phpro/grumphp": "dev-master",
"phpstan/phpstan": "^0.12.0@dev",
"phpunit/phpunit": "8.*",
"sebastian/phpcpd": "^5.0@dev",
"triagens/arangodb": "3.5.*"
},
"autoload": {
"psr-4": {
"LaravelFreelancerNL\\FluentAQL\\": "src"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"repositories": [],
"minimum-stability": "dev"
}
8 changes: 8 additions & 0 deletions docs/core-concepts/arangodb-and-aql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
##ArangoDB
ArangoDB is a multi-model NoSQL database consisting of a key-value store, document store and graph store.

[Read all about ArangoDB here](https://www.arangodb.com/).
## ArangoDB Query Language (AQL)
AQL is a declarative, easy to learn and use query language that allows you to utilize all three of ArangoDB’s data models together fluently.

[Official AQL documentation](https://www.arangodb.com/docs/stable/aql/).
Empty file.
19 changes: 19 additions & 0 deletions docs/core-concepts/terminology.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Terminology

| Term | Meaning |
| :------- | :------------------ |
| AQL | ArangoDB Query Language |
| Entity | A core element of ArangoDB: collections, views, graphs, documents and attributes |
| Collection | A collection of documents; ArangoDB’s NoSQL equivalent of a SQL table|
| View | A calculated ‘collection’ of documents for sophisticated information retrieval queries |
| Document | A data object; ArangoDB’s NoSQL equivalent of a SQL table row|
| Attribute | An atomic piece of data; ArangoDB’s NoSQL equivalent of a SQL table field|
| AQL | ArangoDB Query Language |
| Query | Strictly speaking a set of clauses that question the DB to retrieve data. It has become the term for any kind of command send to a database|
| Statement | A data manipulation query|
| Clause | a constituent component of a query |
| Query Clause | A data retrieval AQL clause |
| Statement Clause | A data manipulation AQL clause |
| Graph Clause | A graph traversal AQL clause |
| Expression | A value or symbol representing a value or database entity |
| Function| Computational expression |
10 changes: 10 additions & 0 deletions docs/use-fluentaql/aqb-facade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# AQB Façade
A façade is included for ease of use.
You can just call it to quickly create new query, for example:
```php
use LaravelFreelancerNL\FluentAQL\Facades\AQB;

AQB::for(‘u’, ‘users’)->filter(‘u.surname’, ‘Stark’)->return(‘u’);
```

> Do not use the façade to express anything other than a subquery as it will break automated data binding.
9 changes: 9 additions & 0 deletions docs/use-fluentaql/build-a-query.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Build a query
You can easily create a new query as follows:
Create a QueryBuilder object and fluently string together query, statement and graph clauses.
```php
use LaravelFreelancerNL\FluentAQL\QueryBuilder;

$qb = new QueryBuilder();
$qb = $qb-> for(‘u’, ‘users’)->filter(‘u.surname’, ‘Stark’)->return(‘u’);
```
20 changes: 20 additions & 0 deletions grumphp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
parameters:
bin_dir: "./vendor/bin"
git_dir: "."
process_timeout: 120
tasks:
phpcsfixer2: ~
phpunit:
testsuite: Unit
metadata:
priority: 100
composer:
no_check_lock: true
composer_normalize: ~
jsonlint: ~
yamllint:
ignore_patterns:
- "#test/(.*).yml#"
testsuites:
git_pre_commit:
tasks: [phpcsfixer2, phpunit, composer, composer_normalize, jsonlint, yamllint]
25 changes: 25 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
bootstrap="vendor/autoload.php"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
beStrictAboutTestsThatDoNotTestAnything="false"
>
<testsuites>
<testsuite name="all">
<directory suffix=".php">tests/</directory>
</testsuite>
<testsuite name="unit">
<directory>tests/unit</directory>
</testsuite>
<testsuite name="int">
<directory>tests/integration</directory>
</testsuite>
</testsuites>
</phpunit>
31 changes: 31 additions & 0 deletions src/API/hasFunctions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
namespace LaravelFreelancerNL\FluentAQL\API;

use LaravelFreelancerNL\FluentAQL\Expressions\FunctionExpression;

/**
* Trait hasFunctions
*
* AQL Function API calls.
*
* @package LaravelFreelancerNL\FluentAQL\API
*/
trait hasFunctions
{
use hasMiscellaneousFunctions;

/**
* 'Catch all' method for AQL functions that haven't been implemented directly in this builder.
*
* @param $functionName
* @param mixed ...$parameters
* @return FunctionExpression
*/
protected function function($functionName, ...$parameters)
{
//Normalize input

//Return a Function Expression
return new FunctionExpression($functionName, $parameters);
}
}
Loading

0 comments on commit 80924b4

Please sign in to comment.