Limit / Offset Pagination

Limit/offset pagination uses take and skip to control the number of records and their starting position.

Understanding Limit/Offset Pagination

The take and skip parameters implement traditional pagination using limits and offsets. This is ideal for page-based navigation, such as "Page 1, Page 2, Page 3".

  • take defines how many records to return.
  • skip defines how many records to skip before starting the result.
  • Commonly used for page navigation (e.g., page 2 = skip: 10, take: 10).
  • Less performant on large datasets because SQL must skip rows internally.

Example Usage: Limit/Offset Pagination

use Lib\Prisma\Classes\Prisma;

$prisma = Prisma::getInstance();
$users = $prisma->user->findMany([
    'orderBy' => [
        'name' => 'asc'
    ],
    'skip' => 10,
    'take' => 10
]);

echo "<pre>";
print_r($users);
echo "</pre>";

    

Best Practices

  • Use limit/offset for small and medium-sized datasets with page navigation.
  • Always combine with orderBy for consistent ordering.
  • For large lists or infinite scroll, use cursor-based pagination instead.