Download the PHP package nahid/qarray without Composer
On this page you can find all versions of the php package nahid/qarray. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package qarray
Short Description QArray is a PHP abstraction for querying array
License MIT
Homepage https://github.com/nahid/qarray
Informations about the package qarray
QArray - Query Engine For Array
QArray is query engine for PHP array data. It helps to developers querying any kind of array data with ORM like feel.
Installation
Implementation
Since QArray is an abstract layer of code, so you have to implement your own system with a lots of pre build functionality.
Lets start our first implementation for JSON data.
Here you see we implement a new engine for JSON data. QueryEngine
is an abstract class, so we have to implement its two abstract function readPath
and parseData
Usage
Our implementation were complete, now we can use this implementation.
Here we develop a class for Products and this class use JsonQueryEngine
for fetch data from JSON file.
Lets see, how to use it.
here is our JSON file data.json
And now we read it to querying data.
Output
Pretty neat, huh?
Let's explore the full API to see what else magic this library can do for you. Shall we?
API
List of API:
- fetch
- find
- at
- from
- select
- except
- then
- collect
- json
- import
- where
- orWhere
- whereIn
- whereNotIn
- whereNull
- whereNotNull
- whereStartsWith
- whereEndsWith
- whereContains
- whereMatch
- whereInstance
- whereDataType
- sum
- count
- size
- max
- min
- avg
- first
- last
- nth
- column
- implode
- exists
- groupBy
- sort
- sortBy
- reset
- copy
- toJson
- keys
- values
- filter
- transform
- each
- pipe
- chunk
- macro
Available operation for where clause
key
-- the property name of the data. Or you can pass a Function here to group multiple query inside it. See details in exampleval
-- value to be matched with. It can be a int, string, bool or even Function - depending on theop
.-
op
-- operand to be used for matching. The following operands are available to use:=
: For weak equality matchingeq
: Same as=
!=
: For weak not equality matchingneq
: Same as!=
==
: For strict equality matchingseq
: Same as==
!==
: For strict not equality matchingsneq
: Same as!==
>
: Check if value of given key in data is Greater than valgt
: Same as>
<
: Check if value of given key in data is Less than vallt
: Same as<
>=
: Check if value of given key in data is Greater than or Equal of valgte
: Same as>=
<=
: Check if value of given key in data is Less than or Equal of vallte
: Same as<=
null
: Check if the value of given key in data is null (val
parameter inwhere()
can be omitted for thisop
)notnull
: Check if the value of given key in data is not null (val
parameter inwhere()
can be omitted for thisop
)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. Theval
parameter should be a RegExp for thisop
.instance
: Check it the value of givenkey
in data has an instance.
example:
Let's say you want to find the 'users' who has id
of 1
. You can do it like this:
You can add multiple where conditions. It'll give the result by AND-ing between these multiple where conditions.
See a detail example here.
orWhere(key, op, val)
Parameters of orWhere()
are the same as where()
. The only difference between where()
and orWhere()
is: condition given by the orWhere()
method will OR-ed the result with other conditions.
For example, if you want to find the users with id of 1
or 2
, you can do it like this:
See detail example here.
whereIn(key, val)
key
-- the property name of the dataval
-- it should be an Array
This method will behave like where(key, 'in', val)
method call.
whereNotIn(key, val)
key
-- the property name of the dataval
-- it should be an Array
This method will behave like where(key, 'notin', val)
method call.
whereNull(key)
key
-- the property name of the data
This method will behave like where(key, 'null')
or where(key, '=', null)
method call.
whereNotNull(key)
key
-- the property name of the data
This method will behave like where(key, 'notnull')
or where(key, '!=', null)
method call.
whereStartsWith(key, val)
key
-- the property name of the dataval
-- it should be a String
This method will behave like where(key, 'startswith', val)
method call.
whereEndsWith(key, val)
key
-- the property name of the dataval
-- it should be a String
This method will behave like where(key, 'endswith', val)
method call.
whereContains(key, val)
key
-- the property name of the dataval
-- it should be a String
This method will behave like where(key, 'contains', val)
method call.
whereDataType(key, val)
key
-- the property name of the dataval
-- it should be a String
This method will behave like whereDataType(key, 'type', val)
method call.
sum(column)
column
-- the property name of the data
Bugs and Issues
If you encounter any bugs or issues, feel free to open an issue at github.
Also, you can shoot me an email to mailto:[email protected] for hugs or bugs.