Git Product home page Git Product logo

querifier's Introduction

Latest Stable Version Build Status License: MIT

Querifier

Installing

composer require paknahad/querifier

Usage

Symfony & Doctrine

<?php
use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory;
use Paknahad\Querifier\Filter;
...
    $psrFactory = new DiactorosFactory();
    $psrRequest = $psrFactory->createRequest($request);

    $filter = new Filter($psrRequest);
    $filter->applyFilter($repository->createQueryBuilder('alias'));

Examples:

Expression:

http://example.com/books?q=title:php^author.name:hamid

Criteria:

http://example.com/books?filter[title]=php&filter[author.name]=hamid

SQL:

SELECT * FROM books AS b INNER JOIN authors AS a ...
WHERE
    b.title = 'php'
    AND
    a.name = 'hamid'

Advanced query:

Expression:

http://example.com/books?q=title:php^(author.name:%hamid%|(publish_date>2017-1-1^publish_date<2017-6-1))

Criteria:

books?filter[title]=php&filter[_c1][author.name][_like]=%hamid%&filter[_c2][publish_date][_gt]=2017-1-1&filter[_c3][publish_date][_lt]=2017-6-1]&filter[_c4][_cmb_and]=_c2,_c3&filter[_cmb_or]=_c4,_c1

SQL:

SELECT * FROM books AS b INNER JOIN authors  AS a …
WHERE
    b.title = 'php' 
    AND
    (
        (
            b.publish_date > '2017-1-1'
            AND
            B.publish_date < '2017-6-1'
        )
        OR
        a.name LIKE '%hamid%'
     )

Expression Parser

Simple query

simple query makes by this structure:

example.com?q=FIELD_NAME:VALUE

Advanced query:

Logical Operators:

  • ^ -> AND
  • | -> OR

Comparision Operators:

  • : -> Equal or LIKE in case there is a % in value.
  • :null => IS NULL
  • <> -> Not Equal or NOT LIKE in case there is a % in value.
  • <>null => IS NOT NULL
  • > -> Greather than
  • < -> Less than

Criteria Parser

Simple query

simple query makes by this structure:

url?filter[FIELD_NAME]=VALUE

Advanced query:

1- Define conditions.

url?filter[CONDITION NAME][FIELD NAME][OPERATOR]=VALUE

2- Combine these conditions together.

url?filter[CONDITION NAME][COMBINE]=CONDITIONS SEPARATED BY “,”
  • Condition name(optional) : An identifier for using in combinations, must be started by “_” and followed by AlphaNumeric characters
  • Operator name(optional , Default: _eq) : Name of an operator such as _eq, _not_eq, _in, _gt, _lt, _like.
  • Combine : use to combine two or more conditions : _cmb_or , _cmb_and

Sorting

  • Ascending on name field: http://example.com/books?sort=name
  • Decending on name field: http://example.com/books?sort=-name
  • Multiple fields: http://example.com/books?sort=city,-name
  • Field on a relation: http://example.com/books?sort=author.name

querifier's People

Contributors

paknahad avatar

Stargazers

 avatar

Watchers

James Cloos 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.