PHP code example of byteferry / rql-parser

1. Go to this page and download the library: Download byteferry/rql-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

byteferry / rql-parser example snippets


$ composer requrire byteferry/rql-Parser

use ByteFerry/RqlParser/Parser;

    $rql_string = 'any(User,columns(id,name,age,gender,address),filter(eq(age,19)))';
    try{
        $query = Parser::parse( $rql_string);
    }catch(\Exception $e){
        // will catch  errror of parse or grammer checking.
    }


use ByteFerry/RqlParser/Parser;

    $rql_string = 'filter(eq(age,19))';
    try{
        $query = Parser::parse( $rql_string, true);
    }catch(\Exception $e){
        // will catch  errror of parse or grammer checking.
    }


        $rql_str= 'all(User,aggr(id,name,age,gender,address,avg(age)),filter(is(created_at, null()), search(Jhon),sort(-id,+age),having(gt(sum(amount),0)),limit(0,20)))'; //,    //,
        $result = Parser::parse($rql_str);
        // Returns:
        /** array (
             0 =>
             ByteFerry\RqlParser\Query::__set_state(array(
                'container' =>
               array (
                 'resource' => 'User',
                 'columns' =>
                 array (
                   0 => 'id',
                   1 => 'name',
                   2 => 'age',
                   3 => 'gender',
                   4 => 'address',
                   5 => 'avg(age)',
                 ),
                 'columns_operator' => 'aggr',
                 'group_by' =>
                 array (
                   0 => 'id',
                   1 => 'name',
                   2 => 'age',
                   3 => 'gender',
                   4 => 'address',
                 ),
                 'filter' =>
                 array (
                   0 => ' created_at is null ',
                 ),
                 'paramaters' =>
                 array (
                   'created_at' => NULL,
                   'sum(amount)' => '0',
                 ),
                 'search' => 'Jhon%',
                 'sort' =>
                 array (
                   0 =>
                   array (
                     0 => 'id',
                     1 => 'DESC',
                   ),
                   1 =>
                   array (
                     0 => 'age',
                     1 => 'ASC',
                   ),
                 ),
                 'having' =>
                 array (
                   0 => ' sum(amount) > 0 ',
                 ),
                 'limit' =>
                 array (
                   0 => '0',
                   1 => '20',
                 ),
                 'operator' => 'all',
                 'query_type' => 'Q_READ',
               ),
             )),
           )

        */