PHP code example of lampager / lampager-idiorm

1. Go to this page and download the library: Download lampager/lampager-idiorm 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/ */

    

lampager / lampager-idiorm example snippets


$cursor = [
    'id' => 3,
    'created_at' => '2017-01-10 00:00:00',
    'updated_at' => '2017-01-20 00:00:00',
];

$result = lampager(ORM::for_table('posts')->where_equal('user_id', 1))
    ->forward()
    ->limit(5)
    ->order_by_desc('updated_at') // ORDER BY `updated_at` DESC, `created_at` DESC, `id` DESC
    ->order_by_desc('created_at')
    ->order_by_desc('id')
    ->seekable()
    ->paginate($cursor)
    ->to_json(JSON_PRETTY_PRINT);

static Paginator create(\ORM|\ORMWrapper $builder): static
Paginator::__construct(\ORM|\ORMWrapper $builder)

Paginator::transform(\Lampager\Query $query): \ORM|\ORMWrapper

Paginator::build(\Lampager\Contracts\Cursor|array $cursor = []): \ORM|\ORMWrapper

Paginator::paginate(\Lampager\Contracts\Cursor|array $cursor = []): \Lampager\idiorm\PaginationResult

object(Lampager\Idiorm\PaginationResult)#1 (5) {
  ["records"]=>
  array(5) {
    [0]=>
    object(ORM)#2 (22) { ... }
    [1]=>
    object(ORM)#3 (22) { ... }
    [2]=>
    object(ORM)#4 (22) { ... }
    [3]=>
    object(ORM)#5 (22) { ... }
    [4]=>
    object(ORM)#6 (22) { ... }
  }
  ["hasPrevious"]=>
  bool(false)
  ["previousCursor"]=>
  NULL
  ["hasNext"]=>
  bool(true)
  ["nextCursor"]=>
  array(2) {
    ["updated_at"]=>
    string(19) "2017-01-18 00:00:00"
    ["created_at"]=>
    string(19) "2017-01-14 00:00:00"
    ["id"]=>
    int(6)
  }
}

Paginator::useFormatter(\Lampager\Formatter|callable $formatter): $this
Paginator::restoreFormatter(): $this
Paginator::process(\Lampager\Query $query, array|\IdiormResultSet $rows): \Lampager\idiorm\PaginationResult

PaginationResult::toArray(): array
PaginationResult::jsonSerialize(): array

PaginationResult::__call(string $name, array $args): mixed
sql
SELECT * FROM (

    SELECT * FROM `posts`
    WHERE `user_id` = 1
    AND (
        `updated_at` = '2017-01-20 00:00:00' AND `created_at` = '2017-01-10 00:00:00' AND `id` > 3
        OR
        `updated_at` = '2017-01-20 00:00:00' AND `created_at` > '2017-01-10 00:00:00'
        OR
        `updated_at` > '2017-01-20 00:00:00'
    )
    ORDER BY `updated_at` ASC, `created_at` ASC, `id` ASC
    LIMIT 1

) `temporary_table`

UNION ALL

SELECT * FROM (

    SELECT * FROM `posts`
    WHERE `user_id` = 1
    AND (
        `updated_at` = '2017-01-20 00:00:00' AND `created_at` = '2017-01-10 00:00:00' AND `id` <= 3
        OR
        `updated_at` = '2017-01-20 00:00:00' AND `created_at` < '2017-01-10 00:00:00'
        OR
        `updated_at` < '2017-01-20 00:00:00'
    )
    ORDER BY `updated_at` DESC, `created_at` DESC, `id` DESC
    LIMIT 6

) `temporary_table`