PHP code example of jonasraoni / query-builder-extensions
1. Go to this page and download the library: Download jonasraoni/query-builder-extensions 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/ */
jonasraoni / query-builder-extensions example snippets
getCount(): int
paginateLazily(Builder $query, int $rows): \Generator
bufferedIterator(Builder $query, array $sortMap, int $rows): \Generator
use JonasRaoni\QueryBuilder\Extensions;
Extensions::extend();
$records = $connection->table('posts')
->select('id', 'date', 'title')
// Will produce an "ORDER BY id DESC, IF(date IS NULL, 0, 1)"
->bufferedIterator(
[
// Maps the given sort expression to the "id" field (must be available in the "SELECT")
'id DESC' => 'id',
// Maps the given sort expression using a callable
'IF(date IS NULL, 0, 1)' => function ($record) {
return $record->date ? 1 : 0;
}
]
);
foreach ($records as $record) {
echo $record->id;
}
use JonasRaoni\QueryBuilder\Extensions;
Extensions::extend();
$records = $connection->table('test')
->select('field')
->orderBy('field')
->paginateLazily(100);
foreach ($records as $record) {
echo $record->id;
}
echo $connection->table('test')->getCount();
use JonasRaoni\QueryBuilder\Extensions;
$queryBuilder = $connection
->table('test')
->select('field')
->orderBy('field');
$records = Extensions::paginateLazily($queryBuilder, 100);
foreach ($records as $record) {
echo $record->id;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.