> ## Documentation Index
> Fetch the complete documentation index at: https://nestrs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# nestrs-sea-orm

> Register a SeaORM connection in the nestrs DI graph — NestJS TypeORM / Sequelize analogue.

TypeORM and Sequelize are Node ORMs. The Rust equivalent this crate binds into the nestrs graph is [SeaORM](https://www.sea-ql.org/SeaORM/). `SeaOrmModule::for_root_async` connects and exports `DatabaseConnection` for injection.

Drizzle stays carved out of workspace members (upstream/MSRV). For Prisma-style access use [`nestrs-prisma`](/ecosystem/database); for raw SQL use `SqlxDatabaseModule`.

## Install

```toml theme={null}
[dependencies]
nestrs = "1.3.0"
nestrs-sea-orm = "1.3.0"
```

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` (same rule as `MongoModule::for_root_async`). Merge the `DynamicModule` with `create_with_modules` so `Arc<DatabaseConnection>` is exported:

```rust theme={null}
use nestrs::prelude::*;
use nestrs_sea_orm::SeaOrmModule;
use sea_orm::DatabaseConnection;
use std::sync::Arc;

#[injectable]
struct UserService {
    db: Arc<DatabaseConnection>,
}

impl UserService {
    async fn ping(&self) -> Result<(), sea_orm::DbErr> {
        let _ = self.db;
        Ok(())
    }
}

#[derive(Default)]
#[injectable]
struct AppState;

#[controller(prefix = "/db")]
struct DbController;

#[routes(state = AppState)]
impl DbController {
    #[get("/")]
    async fn ok() -> &'static str {
        "ok"
    }
}

#[module(controllers = [DbController], providers = [AppState, UserService])]
struct AppModule;

#[tokio::main]
async fn main() {
    let sea = SeaOrmModule::for_root_async("sqlite::memory:")
        .await
        .expect("sqlite memory");

    NestFactory::create_with_modules::<AppModule, _>([sea])
        .listen_graceful(3000)
        .await;
}
```

`DbConn` is a type alias for `DatabaseConnection`. Inject `Arc<DatabaseConnection>` (the registry stores `Arc`).

## Compared with other SQL paths

| Path                                   | When to use                                 |
| -------------------------------------- | ------------------------------------------- |
| `database-sqlx` / `SqlxDatabaseModule` | Raw SQL, `AnyPool`                          |
| `nestrs-prisma`                        | Schema-driven repositories, `prisma_model!` |
| `nestrs-sea-orm`                       | SeaORM entities / Active Record style       |
| `nestrs-drizzle`                       | Not a workspace member in 1.3.0             |

Define SeaORM `Entity` types in your crate and use the injected connection as you would in a standalone SeaORM app.
