Database Query Batching
dldr excels at batching database queries, reducing the number of round trips to your database and significantly improving performance.Basic Database Batching
The most common pattern is batching record lookups by ID:Define your load function
Create a function that accepts an array of keys and returns an array of results:
Database Examples
- PostgreSQL
- Prisma
- MongoDB
- Drizzle
Using PostgreSQL with the
postgres library:Important: Maintaining Order
Your batch function must return results in the same order as the input keys:Handling Errors
ReturnError objects for individual failures:
Using Identity Keys
When your load function returns objects with a different key structure, useidentityKey: