GithubHelp home page GithubHelp logo

govaniso / arangodb-php-aql-generator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tarsislima/arangodb-php-aql-generator

0.0 2.0 0.0 75 KB

AQL Generator For ArangoDb-PHP [Alpha] This is a experimental Aql Query Builder to generate AQL strings.

PHP 100.00%

arangodb-php-aql-generator's Introduction

README

AQL Generator For ArangoDb-PHP [Alpha]

This is a experimental builder to generate Aql Query Strings and is in alpha version.

What is this repository for?

  • Quick summary
  • Version 1.1-alpha

Setup and basic

To run the queries in this examples was used the Statement Class of Arangodb Driver available on Github ArangoDB-PHP

//configure statement
$connection = new Connection($connectionOptions);
$statement = new Statement($connection, array(
                          "query"     => '',
                          "count"     => true,
                          "sanitize"  => true,
                      ));
                      
use tarsys\AqlGen\AqlGen;

  //mount the query
  $query1 = AqlGen::query('u', 'users'); 
    
//execute 
$statement->setQuery($mainQuery->get());
//$statement->bind($mainQuery->getParams()); //if some params has passed

Examples

  • Simple query
   //SIMPLE QUERIES

   $query1 = AqlGen::query('u', 'users'); 

     echo $query1->get();
  // Generate:  FOR u IN users RETURN u

  //WITH filter
   $query1 = AqlGen::query('u', 'users')->filter('u.yearsOld == 20');
  
    echo $query1->get();
/* Generate: 
    FOR u IN users 
    FILTER u.yearsOld == 20
    RETURN u
*/
  • Sub Queries
//Example 1: subquery

  $mainQuery = AqlGen::query('u', 'users'); 

  $locations = AqlGen::query('l', 'locations')->filter('u.id == l.id');

  $mainQuery->subquery($locations)
              ->serReturn('{"user": u, "location": l}');

  echo $mainQuery->get();
 /* Generate this string: 
    FOR u IN users 
       FOR l IN locations 
          FILTER u.id == l.id
    RETURN {`user`:u, `location`:l}
  */
  
  • Filter with bind params
$mainQuery = AqlGen::query('u', 'users')->filter('u.id == @id', ['id'=> 19]); 

$mainQuery->filter('u.name == @name && u.age == @age')->bindParams(['name'=> 'jhon', 'age' => 20]);
$mainQuery->orFilter('u.group == @group')->bindParam('group', 11);
  
echo $mainQuery->get();
/* Generate: 
    FOR u IN users 
       FILTER u.id == @id  && u.name == @name && u.age == @age ||  u.group == @group
    RETURN u
*/

// USE $mainQuery->getParams(); to retrieve bind params
  • Variable assignment
$mainQuery = AqlGen::query('u', 'users')
            ->let('myvar', 'hello')
            ->let('myfriends', AqlGen::query('f','friends') );
 
 echo $mainQuery->get();
 
 /* Generate this string: 
    FOR u IN users 
       LET  myvar = `hello`
       LET  myfriends = ( 
          FOR f IN friends 
          RETURN f
        )
    RETURN u
  */ 
  
  • Result grouping
$mainQuery = AqlGen::query('u', 'users')
            ->collect('myvar', 'u.city', 'g');

echo $mainQuery->get();
 
 /* Generate this string: 
    FOR u IN users 
       COLLECT `myvar` = u.city INTO g
    RETURN u
  */
  • Result sorting
$mainQuery = AqlGen::query('u', 'users')
            ->sort('u.activity', AqlGen::SORT_DESC)
            ->sort(array('u.name','u.created_date')); // asc by default

echo $mainQuery->get();
 
 /* Generate this string: 
    FOR u IN users 
       SORT u.activity DESC, u.name, u.created_date ASC
    RETURN u
  */
  • Configuration
  • Dependencies

Contribution guidelines

  • Give me a feedback/sugestions about this implementation !!Very important!!
  • Writing tests
  • Code review
  • Other guidelines

arangodb-php-aql-generator's People

Contributors

tarsislima avatar

Watchers

James Cloos avatar Govani avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.