Drizzle stays carved out of workspace members. For Prisma-style access use
nestrs-prisma; for raw SQL use SqlxDatabaseModule.
Install
sqlx-sqlite feature (sqlite::memory: and file URLs work out of the box). For Postgres or MySQL, add a direct sea-orm dependency with the matching driver feature (same 1.1 line) in your app.
Connect and inject
for_root_async must finish before NestFactory::create. Merge the DynamicModule with create_with_modules so Arc<DatabaseConnection> is exported:
Ambient transactions
Applyinstall_sea_orm_transactional_middleware with from_fn_with_state(db, …). Inside the request, Repo methods prefer the ambient transaction. 2xx / 3xx / 4xx → commit, 5xx → rollback.
Bind — authorized path → row
NestRS hands youBind<Read, UsersService> as a handler parameter. In nestrs, load once with deny-closed policy:
BindError maps to 401 (missing authz), 403 (denied), 404 (missing / invisible), 500 (db).
Attach ability onto request extensions when you build custom extractors:
Expose — one model type for OpenAPI
Deriveschemars::JsonSchema on the entity Model (or a view DTO) and register it once:
SimpleObject / resolvers so OpenAPI and GraphQL cannot drift.
Row-level authz
RepoError::Denied (or Ok(None) for invisible reads).
Route posture (umbrella)
GraphQL DataLoader + SeaORM
Register a per-request loader that batches throughRepo (sees the ambient tx when the HTTP middleware is installed):