Skip to content

Adding cursor pagination on Select #27

In progress

Description

@Baptouuuu

This needs #26

Something like:

$select
    ->cursor(
        Cursor::of($column1, asc)
            ->and($column2, desc),
    )
    ->limit(1_000);

This would translate to SELECT * FROM x ORDER BY column1 ASC, column2 DESC LIMIT 1000. In other words it simply apply ordering on the select.

For the next page it would be written as:

$select
    ->cursor(
        Cursor::on($column1, asc)
            ->and($column2, desc)
            ->following($previousRow),
    )
    ->limit(1_000);

If the previous row doesn't contain the columns of the cursor then it will throw a logic exception.

This would translate to SELECT * FROM x WHERE column1 > $previousRow.column1 OR (column1 = $previousRow.column1 AND (column2 < $previousRow.column2)) ORDER BY column1 ASC, column2 DESC.

Each column is ordered relative to the previous one, this why it needs the complex filtering.

But once again the cursor is a shortcut for orderBy and where.

Note

Instead of having a new cursor method, maybe a new via(callable(Select): Select): Select (similar to Sequence::via() from innmind/immutable) would be better as it allows further composition extraction.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions