Skip to main content
TypeORM and Sequelize are Node ORMs. This crate binds SeaORM into the nestrs DI graph and adds the data-layer pieces Nest / NestRS teams expect: Drizzle stays carved out of workspace members. For Prisma-style access use nestrs-prisma; for raw SQL use SqlxDatabaseModule.

Install

This crate enables SeaORM’s 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

Apply install_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 you Bind<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

Derive schemars::JsonSchema on the entity Model (or a view DTO) and register it once:
Reuse the same type in GraphQL SimpleObject / resolvers so OpenAPI and GraphQL cannot drift.

Row-level authz

Authorized helpers are deny-closed: missing ability / failed predicate → RepoError::Denied (or Ok(None) for invisible reads).

Route posture (umbrella)

GraphQL DataLoader + SeaORM

Register a per-request loader that batches through Repo (sees the ambient tx when the HTTP middleware is installed):

Compared with other SQL paths