📄️ Setup
Installation
📄️ Usage
slonik-trpc allows you to create a loader for each SQL query. With this loader, you can filter, sort, and paginate your data with ease, all while leveraging the power and efficiency of SQL.
📄️ Offset-based pagination
Offset-based pagination allows you to specify the number of items to take and skip when requesting a page of results. This can be useful when working with large datasets and you only need a portion of the data at a time.
📄️ Usage with tRPC
Add a query that uses getLoadArgs and loadPagination from the postsLoader to return data
📄️ Filtering
When building views, you have the possibility to declare filters.
📄️ Authorization
The constraints option can be used for the authorization logic of the loader.
📄️ Overfetching
Selecting groups of fields in a query can help you organize your data more effectively and avoid overfetching.
📄️ Virtual fields
Declare any fields you want to process in typescript as virtual fields.
📄️ Sorting
To add sorting to your data, you can use the sortableColumns option. This allows you to specify the columns that can be sorted, along with their corresponding sorting expressions. For example:
📄️ Distinct on
DISTINCT ON is a powerful PostgreSQL feature. To use it with your dataloader, you need to specify the sortableColumns option, same as with orderBy.
📄️ Cursor-based pagination
To use cursor-based pagination, start by specifying takeCursors: true in your options. This will return a startCursor and endCursor in the pagination response.
📄️ Aggregating
To group your data, you can use the groupBy fragment option of the query. This allows you to specify the GROUP BY fragment that will be applied to your query:
📄️ Plugins
You can use plugins to customize the loaders further.
📄️ Slonik
This is an abbreviated guide to get started with slonik for the purposes of this tutorial, which is just a toy example.
📄️ Classic Filtering method (DEPRECATED)
This method has been deprecated. Use buildView to create filters instead.