Skip to content

Commit

Permalink
Merge pull request #58 from nahid/v6.0
Browse files Browse the repository at this point in the history
V6.0
  • Loading branch information
nahid authored Aug 22, 2020
2 parents 8b38cea + 0696cbe commit 0522738
Show file tree
Hide file tree
Showing 19 changed files with 129 additions and 1,962 deletions.
119 changes: 67 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ Hey due, please help me out for daily improve this project

[![Beerpay](https://beerpay.io/nahid/jsonq/badge.svg)](https://beerpay.io/nahid/jsonq)



## NOTE

> From the version JsonQ 6.0 all the features rewrite from [QAarray](https://github.com/nahid/qarray). After a long run we noticed that Query Engine of JsonQ should be seperate. Becouse people want to query over various types of data like CSV, YAML, XML. So if we keep the query engine tightly coupled with this project its make no sense. Thats why we move the Query Engine part and develop a new package [QAarray](https://github.com/nahid/qarray). Qarray is designed for queryng over native PHP array and anyone can implement their own Engine, like JsonQ.


>
>
> ### Please do not update to >= 6.0 version directly from bellow


## Installation

```
Expand Down Expand Up @@ -42,33 +56,33 @@ Let's see a quick example:
```json
//data.json
{
"name": "products",
"description": "Features product list",
"vendor":{
"name": "Computer Source BD",
"email": "[email protected]",
"website":"www.example.com"
},
"users":[
{"id":1, "name":"Johura Akter Sumi", "location": "Barisal"},
{"id":2, "name":"Mehedi Hasan Nahid", "location": "Barisal"},
{"id":3, "name":"Ariful Islam", "location": "Barisal"},
{"id":4, "name":"Suhel Ahmed", "location": "Sylhet"},
{"id":5, "name":"Firoz Serniabat", "location": "Gournodi"},
{"id":6, "name":"Musa Jewel", "location": "Barisal", "visits": [
{"name": "Sylhet", "year": 2011},
{"name": "Cox's Bazar", "year": 2012},
{"name": "Bandarbar", "year": 2014}
]}
],
"products": [
{"id":1, "user_id": 2, "city": "bsl", "name":"iPhone", "cat":1, "price": 80000},
{"id":2, "user_id": 2, "city": null, "name":"macbook pro", "cat": 2, "price": 150000},
{"id":3, "user_id": 2, "city": "dhk", "name":"Redmi 3S Prime", "cat": 1, "price": 12000},
{"id":4, "user_id": 1, "city": null, "name":"Redmi 4X", "cat":1, "price": 15000},
{"id":5, "user_id": 1, "city": "bsl", "name":"macbook air", "cat": 2, "price": 110000},
{"id":6, "user_id": 2, "city": null, "name":"macbook air 1", "cat": 2, "price": 81000}
]
"name": "products",
"description": "Features product list",
"vendor":{
"name": "Computer Source BD",
"email": "[email protected]",
"website":"www.example.com"
},
"users":[
{"id":1, "name":"Johura Akter Sumi", "location": "Barisal"},
{"id":2, "name":"Mehedi Hasan Nahid", "location": "Barisal"},
{"id":3, "name":"Ariful Islam", "location": "Barisal"},
{"id":4, "name":"Suhel Ahmed", "location": "Sylhet"},
{"id":5, "name":"Firoz Serniabat", "location": "Gournodi"},
{"id":6, "name":"Musa Jewel", "location": "Barisal", "visits": [
{"name": "Sylhet", "year": 2011},
{"name": "Cox's Bazar", "year": 2012},
{"name": "Bandarbar", "year": 2014}
]}
],
"products": [
{"id":1, "user_id": 2, "city": "bsl", "name":"iPhone", "cat":1, "price": 80000},
{"id":2, "user_id": 2, "city": null, "name":"macbook pro", "cat": 2, "price": 150000},
{"id":3, "user_id": 2, "city": "dhk", "name":"Redmi 3S Prime", "cat": 1, "price": 12000},
{"id":4, "user_id": 1, "city": null, "name":"Redmi 4X", "cat":1, "price": 15000},
{"id":5, "user_id": 1, "city": "bsl", "name":"macbook air", "cat": 2, "price": 110000},
{"id":6, "user_id": 2, "city": null, "name":"macbook air 1", "cat": 2, "price": 81000}
]
}
```

Expand Down Expand Up @@ -250,31 +264,31 @@ This is an alias method of `from()` and will behave exactly like that. See examp
* `val` -- value to be matched with. It can be a _int_, _string_, _bool_ or even _Function_ - depending on the `op`.
* `op` -- operand to be used for matching. The following operands are available to use:

* `=` : For weak equality matching
* `eq` : Same as `=`
* `!=` : For weak not equality matching
* `neq` : Same as `!=`
* `==` : For strict equality matching
* `seq` : Same as `==`
* `!==` : For strict not equality matching
* `sneq` : Same as `!==`
* `>` : Check if value of given **key** in data is Greater than **val**
* `gt` : Same as `>`
* `<` : Check if value of given **key** in data is Less than **val**
* `lt` : Same as `<`
* `>=` : Check if value of given **key** in data is Greater than or Equal of **val**
* `gte` : Same as `>=`
* `<=` : Check if value of given **key** in data is Less than or Equal of **val**
* `lte` : Same as `<=`
* `null` : Check if the value of given **key** in data is **null** (`val` parameter in `where()` can be omitted for this `op`)
* `notnull` : Check if the value of given **key** in data is **not null** (`val` parameter in `where()` can be omitted for this `op`)
* `in` : Check if the value of given **key** in data is exists in given **val**. **val** should be a plain _Array_.
* `notin` : Check if the value of given **key** in data is not exists in given **val**. **val** should be a plain _Array_.
* `startswith` : Check if the value of given **key** in data starts with (has a prefix of) the given **val**. This would only works for _String_ type data.
* `endswith` : Check if the value of given **key** in data ends with (has a suffix of) the given **val**. This would only works for _String_ type data.
* `contains` : Check if the value of given **key** in data has a substring of given **val**. This would only works for _String_ type data.
* `match` : Check if the value of given **key** in data has a Regular Expression match with the given **val**. The `val` parameter should be a **RegExp** for this `op`.
* `macro` : It would try to match the value of given **key** in data executing the given `val`. The `val` parameter should be a **Function** for this `op`. This function should have a matching logic inside it and return **true** or **false** based on that.
* `=` : For weak equality matching
* `eq` : Same as `=`
* `!=` : For weak not equality matching
* `neq` : Same as `!=`
* `==` : For strict equality matching
* `seq` : Same as `==`
* `!==` : For strict not equality matching
* `sneq` : Same as `!==`
* `>` : Check if value of given **key** in data is Greater than **val**
* `gt` : Same as `>`
* `<` : Check if value of given **key** in data is Less than **val**
* `lt` : Same as `<`
* `>=` : Check if value of given **key** in data is Greater than or Equal of **val**
* `gte` : Same as `>=`
* `<=` : Check if value of given **key** in data is Less than or Equal of **val**
* `lte` : Same as `<=`
* `null` : Check if the value of given **key** in data is **null** (`val` parameter in `where()` can be omitted for this `op`)
* `notnull` : Check if the value of given **key** in data is **not null** (`val` parameter in `where()` can be omitted for this `op`)
* `in` : Check if the value of given **key** in data is exists in given **val**. **val** should be a plain _Array_.
* `notin` : Check if the value of given **key** in data is not exists in given **val**. **val** should be a plain _Array_.
* `startswith` : Check if the value of given **key** in data starts with (has a prefix of) the given **val**. This would only works for _String_ type data.
* `endswith` : Check if the value of given **key** in data ends with (has a suffix of) the given **val**. This would only works for _String_ type data.
* `contains` : Check if the value of given **key** in data has a substring of given **val**. This would only works for _String_ type data.
* `match` : Check if the value of given **key** in data has a Regular Expression match with the given **val**. The `val` parameter should be a **RegExp** for this `op`.
* `macro` : It would try to match the value of given **key** in data executing the given `val`. The `val` parameter should be a **Function** for this `op`. This function should have a matching logic inside it and return **true** or **false** based on that.

**example:**

Expand Down Expand Up @@ -603,6 +617,7 @@ This package has also different language support.
- [Go JsonQ](https://github.com/thedevsaddam/gojsonq) developed by [Saddam H](https://github.com/thedevsaddam) - Upcoming

## Support on Beerpay

Hey dude! Help me out for a couple of :beers:!

[![Beerpay](https://beerpay.io/nahid/jsonq/badge.svg?style=beer-square)](https://beerpay.io/nahid/jsonq) [![Beerpay](https://beerpay.io/nahid/jsonq/make-wish.svg?style=flat-square)](https://beerpay.io/nahid/jsonq?focus=wish)
14 changes: 9 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@
"keywords": ["json", "jsonq", "query"],
"homepage": "https://github.com/nahid/jsonq",
"type": "library",
"license": "CC0-1.0",
"license": "MIT",
"authors": [
{
"name": "Nahid Bin Azhar",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.5.0"
"php": ">=5.6",
"ext-json": "*",
"nahid/qarray": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8 || ^5.0",
"symfony/var-dumper": "^3.4",
"graham-campbell/testbench": "^3.1"
"symfony/var-dumper": "^3.4"
},
"autoload": {
"psr-4": {
"Nahid\\JsonQ\\": "src/"
}
},
"files": [
"helpers/jsonq.php"
]
},
"autoload-dev": {
"psr-4": {
Expand Down
7 changes: 0 additions & 7 deletions config/jsonq.php

This file was deleted.

13 changes: 9 additions & 4 deletions examples/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@
//});
//

$jq = new Jsonq('data.json');
//$jq = new Jsonq('data.json');

try {
$result = $jq->from('users')
$data = file_get_contents('data.json');
// This will remove unwanted characters.
// Check http://www.php.net/chr for details

$result = jsonq($data)
->from('users')
->where('visits.year', '=', 2010)
->sum('visits.year');
->get();
dump($result);
} catch (\Nahid\JsonQ\Exceptions\ConditionNotAllowedException $e) {

} catch (\Nahid\JsonQ\Exceptions\NullValueException $e) {

}
}
11 changes: 11 additions & 0 deletions helpers/jsonq.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

if (!function_exists('jsonq')) {
function jsonq($jsonData)
{
if (!is_string($jsonData)) throw new \Nahid\QArray\Exceptions\InvalidJsonException();

$json = new Nahid\JsonQ\Jsonq();
return $json->collect($json->parseData($jsonData));
}
}
Loading

0 comments on commit 0522738

Please sign in to comment.