This is simple library for easy getting / setting data from MySQL / SQLite databases.
__construct(PDO $connection, $scheme=[])
Methods for working with scheme:
setCollectionScheme($collectionName, $scheme)
setScheme($scheme)
getScheme()
Methods for configure select:
__get($collectionName)
collection($collectionName)
limit($limit, $skip)
sort($conditions=[])
filter($conditions=[])
populate($fields=[])
Methods for select data:
all($fields=[])
one($fields=[])
first($fields=[])
last($fields=[])
find(...)
Methods for changing data:
save($data=[], $returnRecord)
batchSave()
remove($ids)
- param
$name
Name of collection - return
Storage
Link to current object
Set inner cursor to collection with $name
.
Example:
$storage->collection('users');
- param
$conditions=[]
Conditions for sorting - return
Storage
Link to current object
Example:
$storage->collection('users')->sort([ 'name'=>-1, 'id'=>1 ])->all();
$conditions
is key/value array where key is field name and value is type of sorting: -1
is descending sorting, 1
is ascending sorting.
- param
$conditions=[]
Conditions for filtering - return
Storage
Link to current object
Example:
$storage->collection('users')->filter([ 'name'=>'Piter' ])->all();
$storage->collection('users')->filter([ 'name'=>['Piter', 'Mike'] ])->all();
- param
fields=[]
List of fields - return
Storage
Link to current object
$fields
is list of fields that need to be linked with other tables by one to many or many to many relation.
Example:
$storage->collection('users')->populate([ 'user', 'comments' ])->all();
- param
fields=[]
List of fields - return
Array
List of data
$fields
is list of fields that will be returned. If $fields
is empty array - will be returned all fields.