ormer-derive 0.1.19

A minimalist ORM framework that supports SQLite, PostgreSQL, MySQL, and SqlServer
Documentation

ormer

version status

English | 简体中文

A minimalist ORM framework that supports SQLite, PostgreSQL, MySQL, and SqlServer.

Online Documentation

Quick Example

#[derive(Debug, ormer::Model)]
#[table = "users"]
struct User {
    #[primary(auto)]
    id: i32,
    name: String,
    age: i32,
    email: Option<String>,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // connect to database and create table
    let db = ormer::Database::connect(ormer::DbType::Sqlite, ":memory:").await?;
    db.create_table::<User>().execute().await?;

    // insert data
    db.insert(&User {
        id: 1,
        name: "Alice".to_string(),
        age: 18,
        email: None,
    })
    .execute()
    .await?;

    // query data
    let users = db
        .select::<User>()
        .filter(|p| p.age.ge(18))
        .collect::<Vec<_>>()
        .await?;
    println!("users: {users:?}");

    Ok(())
}