Git Product home page Git Product logo

eql's Introduction

                                                                      
EEEEEEEEEEEEEEEEEEEEEE     QQQQQQQQQ     LLLLLLLLLLL                  
E::::::::::::::::::::E   QQ:::::::::QQ   L:::::::::L                  
E::::::::::::::::::::E QQ:::::::::::::QQ L:::::::::L                  
EE::::::EEEEEEEEE::::EQ:::::::QQQ:::::::QLL:::::::LL                  
  E:::::E       EEEEEEQ::::::O   Q::::::Q  L:::::L                    
  E:::::E             Q:::::O     Q:::::Q  L:::::L                    
  E::::::EEEEEEEEEE   Q:::::O     Q:::::Q  L:::::L                    
  E:::::::::::::::E   Q:::::O     Q:::::Q  L:::::L                    
  E:::::::::::::::E   Q:::::O     Q:::::Q  L:::::L                    
  E::::::EEEEEEEEEE   Q:::::O     Q:::::Q  L:::::L                    
  E:::::E             Q:::::O  QQQQ:::::Q  L:::::L                    
  E:::::E       EEEEEEQ::::::O Q::::::::Q  L:::::L         LLLLLL     
EE::::::EEEEEEEE:::::EQ:::::::QQ::::::::QLL:::::::LLLLLLLLL:::::L     
E::::::::::::::::::::E QQ::::::::::::::Q L::::::::::::::::::::::L     
E::::::::::::::::::::E   QQ:::::::::::Q  L::::::::::::::::::::::L     
EEEEEEEEEEEEEEEEEEEEEE     QQQQQQQQ::::QQLLLLLLLLLLLLLLLLLLLLLLLL     
                                   Q:::::Q                            
                                    QQQQQQ

Build Status Maintainability Test Coverage

Overview

This project will a try to be a php equivalent of elasticsql.

Currently support:

  • sql and expression
  • sql or expression
  • equal(=) support
  • not equal(!=) support
  • gt(>) support
  • gte(>=) support
  • lt(<) support
  • lte(<=) support
  • sql in (eg. id in (1,2,3) ) expression
  • sql not in (eg. id not in (1,2,3) ) expression
  • paren bool support (eg. where (a=1 or b=1) and (c=1 or d=1))
  • sql like expression (currently use match phrase, perhaps will change to wildcard in the future)
  • sql order by support
  • sql limit support
  • sql not like expression
  • field missing check
  • support aggregation like count(*), count(field), min(field), max(field), avg(field)
  • support aggregation like stats(field), extended_stats(field), percentiles(field) which are not standard sql function
  • null check expression(is null/is not null)
  • join expression
  • having support

Usage

> composer require meysampg/eql

Demo :

<?php

namespace Sample;

use Meysampg\Eql\Parser;

$sql = "
select * from aaa
where a=1 and x = '三个男人'
and create_time between '2015-01-01T00:00:00+0800' and '2016-01-01T00:00:00+0800'
and process_id > 1 order by id desc limit 100,10
";

function main() 
{
    $dsl = Parser::buildFrom($sql);
    print_r(json_encode($dsl));
}

will produce :

{
    "query": {
        "bool": {
            "must": [
                {
                    "match": {
                        "a": {
                            "query": "1",
                            "type": "phrase"
                        }
                    }
                },
                {
                    "match": {
                        "x": {
                            "query": "三个男人",
                            "type": "phrase"
                        }
                    }
                },
                {
                    "range": {
                        "create_time": {
                            "from": "2015-01-01T00:00:00+0800",
                            "to": "2016-01-01T00:00:00+0800"
                        }
                    }
                },
                {
                    "range": {
                        "process_id": {
                            "gt": "1"
                        }
                    }
                }
            ]
        }
    },
    "from": 100,
    "size": 10,
    "sort": [
        {
            "id": "desc"
        }
    ]
}

If your sql contains some keywords, eg. order, timestamp, don't forget to escape these fields as follows:

select * from `order` where `timestamp` = 1 and `desc`.id > 0

eql's People

Contributors

meysampg avatar paknahad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.