Overview
Query
is a helper function that allows you to query the data from the database through API route. It supports pagination, filtering, and sorting.
URL Parameters
Here's an example of a URL with query parameters that you can use:
code
Reserved parameters:
- _skip: Skip the first N items (default: 0)
- _take: Take the first N items (default: 20)
- _sort: Sort items by a column in
asc
ordesc
order (e.g., name:asc)
Other query parameters are used to filter data. These are flattened objects that you can pass to filtering conditions for Prisma. Here's a URL with an advanced filtering example:
code
It will be parsed into:
json
How to Use
You need to wrap it with the Prisma client's findMany
method in an API route. Here's an example of how to use it:
ts
Also, you can append it with the fixed where condition or with other findMany
arguments:
ts