🐚 An async & dynamic ORM for Rust
[](https://crates.io/crates/sea-orm) [](https://docs.rs/sea-orm) [](https://github.com/SeaQL/sea-orm/actions/workflows/rust.yml) Built with 🔥 by 🌊🦀🐚Inspired by ActiveRecord, Eloquent and TypeORM, SeaORM aims to provide you an intuitive and ergonomic API to make working with databases in Rust a first-class experience.
markdown
This is an early release of SeaORM, the API is not stable yet.
Relying on SQLx, SeaORM is a new library with async support from day 1.
Built upon SeaQuery, SeaORM allows you to build complex queries without 'fighting the ORM'.
Use mock connections to write unit tests for your logic.
Quickly build services that join, filter, sort and paginate data in APIs.
```rust
// find all models
let cakes: Vec
// find and filter
let chocolate: Vec
// find one model
let cheese: Option
// find related models (lazy)
let fruits: Vec
// find related models (eager)
let cakewithfruits: Vec<(cake::Model, Vec
```
```rust let apple = fruit::ActiveModel { name: Set("Apple".to_owned()), ..Default::default() // no need to set primary key };
let pear = fruit::ActiveModel { name: Set("Pear".to_owned()), ..Default::default() };
// insert one let res: InsertResult = Fruit::insert(pear).exec(db).await?;
println!("InsertResult: {}", res.lastinsertid);
// insert many Fruit::insert_many(vec![apple, pear]).exec(db).await?; ```
```rust use seaorm::seaquery::{Expr, Value};
let pear: Option
pear.name = Set("Sweet pear".to_owned());
// update one let pear: fruit::ActiveModel = Fruit::update(pear).exec(db).await?;
// update many: UPDATE "fruit" SET "cakeid" = NULL WHERE "fruit"."name" LIKE '%Apple%' Fruit::updatemany() .col_expr(fruit::Column::CakeId, Expr::value(Value::Null)) .filter(fruit::Column::Name.contains("Apple")) .exec(db) .await?;
```
```rust let banana = fruit::ActiveModel { id: Unset(None), name: Set("Banana".to_owned()), ..Default::default() };
// create, because primary key id
is Unset
let mut banana = banana.save(db).await?;
banana.name = Set("Banana Mongo".to_owned());
// update, because primary key id
is Set
let banana = banana.save(db).await?;
```
```rust
let orange: Option
// delete one fruit::Entity::delete(orange).exec(db).await?; // or simply orange.delete(db).await?;
// delete many: DELETE FROM "fruit" WHERE "fruit"."name" LIKE 'Orange' fruit::Entity::delete_many() .filter(fruit::Column::Name.contains("Orange")) .exec(db) .await?;
```
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.