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
$nameName of collection - return
StorageLink to current object
Set inner cursor to collection with $name.
Example:
$storage->collection('users');
- param
$conditions=[]Conditions for sorting - return
StorageLink 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
StorageLink 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
StorageLink 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
ArrayList of data
$fields is list of fields that will be returned. If $fields is empty array - will be returned all fields.