How to Use SeaORM in Rust

Use SeaORM in Rust by defining entities with DeriveEntityModel and connecting to a database via the Database trait to execute type-safe queries.

Use SeaORM by adding the crate to your dependencies, defining entities with the DeriveEntityModel macro, and executing queries via the Database connection.

use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "users")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i32,
    pub name: String,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}

#[tokio::main]
async fn main() {
    let db = Database::connect("sqlite::memory:").await.unwrap();
    let users = User::find().all(&db).await.unwrap();
}