Prisma Query Builder (@explita/prisma-query-builder) bridges the gap between Prisma ORM's ergonomic model mapping and the raw expressive power of SQL. Engineered for complex, real-world data queries where standard findMany falls short, it offers a clean, declarative API for multi-table joins, subqueries, complex boolean trees, advanced operators, and zero-boilerplate pagination with 100% TypeScript type inference.
The library operates in two flexible paradigms. In extension mode via queryBuilderExtension(), it seamlessly augments the Prisma Client with prisma.$extends(), attaching prisma.queryBuilder() directly with optional global defaults (driver selection, pagination limits, caching, and timeouts). In standalone mode, the standalone queryBuilder() function accepts any Prisma client instance or generates parameterized raw SQL strings (query.raw, query.toSQL(), query.toParams()) for manual execution via prisma.$queryRaw.
Multi-dialect support covers PostgreSQL, MySQL, and SQLite. Beyond common operators (eq, neq, gt, gte, lt, lte, in, notIn, like, notLike, btw, startsWith, endsWith, contains, regexp), it delivers native Postgres-specific extensions including case-insensitive iLike, array operations (overlap, containedBy), JSON key inspection (jsonHasKey, jsonHasAnyKeys, jsonHasAllKeys), as well as subquery checks via EXISTS and NOT_EXISTS.
Built for production scale, Prisma Query Builder includes first-class pagination via .exec.paginate() (or .exec().paginate()), returning a type-safe [data, meta] tuple complete with totalCount, pageCount, isFirstPage, isLastPage, and boundary offsets. For high-throughput workloads, it features optional in-memory query caching with TTL automatic invalidation, and strict query execution timeouts (queryTimeout) to prevent runaway database locks.