1. Go to this page and download the library: Download emsifa/laci library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
emsifa / laci example snippets
use Emsifa\Laci\Collection;
n(__DIR__.'/users.json');
// select * from books.json where author[name] = 'Jane Doe'
$bookCollection->where('author.name', 'Jane Doe')->get();
// select * from books.json where star > 3
$bookCollection->where('star', '>', 3)->get();
// select * from books.json where star > 3 AND author[name] = 'Jane Doe'
$bookCollection->where('star', '>', 3)->where('author.name', 'Jane Doe')->get();
// select * from books.json where star > 3 OR author[name] = 'Jane Doe'
$bookCollection->where('star', '>', 3)->orWhere('author.name', 'Jane Doe')->get();
// select * from books.json where (star > 3 OR author[name] = 'Jane Doe')
$bookCollection->where(function($book) {
return $book['star'] > 3 OR $book['author.name'] == 'Jane Doe';
})->get();
// select author, title from books.json where star > 3
$bookCollection->where('star', '>', 3)->get(['author.name', 'title']);
// select author[name] as author_name, title from books.json where star > 3
$bookCollection->where('star', '>', 3)->get(['author.name:author_name', 'title']);
// select * from books.json order by star asc
$bookCollection->sortBy('star')->get();
// select * from books.json order by star desc
$bookCollection->sortBy('star', 'desc')->get();
// sorting calculated value
$bookCollection->sortBy(function($row) {
return $row['star'] + $row['views'];
}, 'desc')->get();
// select * from books.json offset 4
$bookCollection->skip(4)->get();
// select * from books.json limit 10 offset 4
$bookCollection->take(10, 4)->get();
$userCollection = new Collection('db/users.json');
$bookCollection = new Collection('db/books.json');
// get user with 'books'
$userCollection->withMany($bookCollection, 'books', 'author.email', '=', 'email')->get();
// get books with 'user'
$bookCollection->withOne($userCollection, 'user', 'email', '=', 'author.email')->get();