GithubHelp home page GithubHelp logo

rql-parser's Introduction

ByteFerry RQL-Parser

ByteFerry RQL-Parser is used for parsing the RQL text to the paramaters with PHP array structure for the calling of php methods.

Build Status StyleCI Codecov branch Latest Stable Version Total Downloads License

中文(Chinese)

This library consists of the following parts:

  • lexer for tokenization RQL code
  • parser for creating abstract syntax tree
  • builder using simplized ABNF of RQL

Features

  • High performance. The size of source code is less than 60KB.
  • It is fully according the compile specification.
  • Friendly for development with the checking of RQL grammer.
  • Support the both reading and writing query.
  • Support filter sort search and pagination
  • Fully tested with phpUnit.
  • Zero dependencies.

Why RQL

  • For the same data, RQL has much fewer bytes than JSON.
  • Simple and easy to learn.
  • RQL will make the API interface more flexible
  • RQL is more suitable for small and medium-sized projects than GraphQL.
  • RQL can save you more development time.

Installation

$ composer requrire byteferry/rql-Parser

Usage

  • parser a full query
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.
    }

if sucess, it will return a QueryInterface.

  • parser a query segment of RQL query
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.
    }

Here is a complex example. (Not a real query, but returns all properties)

        $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',
               ),
             )),
           )

        */

We could see that the parser add groupby automatically, and returns the property parematers for validation.

Documentation

RQL Documentation

Contribution

  1. Fork the repository
  2. Create Feat_xxx branch
  3. Commit your code
  4. Create Pull Request

Donation

If you find this project useful, you can buy author a glass of juice 🍹

donate

License

MIT

Copyright [2020] ByteFerry [email protected]

rql-parser's People

Contributors

bardoqi avatar byteferry avatar

Stargazers

 avatar

Watchers

 avatar  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.