Join our Discord server to chat with others in the SeaQL community!
Async
Relying on SQLx, SeaORM is a new library with async support from day 1.
Dynamic
Built upon SeaQuery, SeaORM allows you to build complex queries without 'fighting the ORM'.
Testable
Use mock connections to write unit tests for your logic.
Service Oriented
Quickly build services that join, filter, sort and paginate data in APIs.
```rust use sea_orm::entity::prelude::*;
pub struct Model { #[seaorm(primarykey)] pub id: i32, pub name: String, }
pub enum Relation { #[seaorm(hasmany = "super::fruit::Entity")] Fruit, }
impl Related
```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 pear = pear.insert(db).await?;
// 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::Model = pear.update(db).await?;
// update many: UPDATE "fruit" SET "cakeid" = NULL WHERE "fruit"."name" LIKE '%Apple%' Fruit::updatemany() .col_expr(fruit::Column::CakeId, Expr::value(Value::Int(None))) .filter(fruit::Column::Name.contains("Apple")) .exec(db) .await?;
```
```rust let banana = fruit::ActiveModel { id: NotSet, name: Set("Banana".to_owned()), ..Default::default() };
// create, because primary key id
is NotSet
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
// delete one
let orange: Option
// or simply
let orange: Option
// 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.