Understanding Limit/Offset Pagination
The take and skip parameters implement traditional limit/offset pagination. This method allows you to control the number of records returned and the starting point of the result set.
takedefines how many records to return.skipdefines how many records to skip before starting the result set.- Commonly used for paginated lists where users navigate by page number (e.g., page 2 =
skip: 10,take: 10). - May be less performant for large datasets due to skipping rows internally in SQL.
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 for small or medium-sized datasets where page jumps are frequent.
- Combine with
orderByfor consistent result ordering across pages. - For large datasets or infinite scrolling, prefer
cursor-based pagination to avoid performance bottlenecks.