SQL
@opra/sqb integrates SQB — a SQL query builder and ORM for Node.js — with the OPRA framework. It provides two service base classes that handle codec generation, filter translation, projection, pagination, lifecycle hooks, and the for(context) per-request wiring, leaving your code focused on business logic.
npm install @opra/sqb @sqb/connect @sqb/builder
You also need a dialect adapter, for example:
npm install @sqb/postgres
Which service should I use?
| Your data shape | Use |
|---|---|
| A table (or view) with multiple rows, each identified by a key | SqbCollectionService |
| A table that always holds exactly one row | SqbSingletonService |
Both share the same configuration, the same for(context) pattern, and the same lifecycle hook interface.
Service hierarchy
SqbServiceBase shared base: db connection, withTransaction
└── SqbEntityService CRUD primitives + lifecycle hooks + interceptor
├── SqbCollectionService full CRUD on a table or view
└── SqbSingletonService single-row operations (no key argument)
Guides
- Getting Started — first service, database connection, NestJS wiring
- Querying — filter, projection, sort, pagination
- Mutations — create, update, delete; PatchDTO and SQL expressions
- Lifecycle Hooks — validation, audit logging, computed fields
- Interceptors — cross-cutting logic
- Transactions — multi-table atomic operations