Skip to main content

What's new in SeaORM 0.2.4

ยท 2 min read
SeaQL Team
Chris Tsang

๐ŸŽ‰ We are pleased to release SeaORM 0.2.4 today! Some feature highlights:

Better ergonomic when working with custom select list#

[#208] Use Select::into_values to quickly select a custom column list and destruct as tuple.

use sea_orm::{entity::*, query::*, tests_cfg::cake, DeriveColumn, EnumIter};
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]enum QueryAs {    CakeName,    NumOfCakes,}
let res: Vec<(String, i64)> = cake::Entity::find()    .select_only()    .column_as(cake::Column::Name, QueryAs::CakeName)    .column_as(cake::Column::Id.count(), QueryAs::NumOfCakes)    .group_by(cake::Column::Name)    .into_values::<_, QueryAs>()    .all(&db)    .await?;
assert_eq!(    res,    vec![("Chocolate Forest".to_owned(), 2i64)]);

Contributed by:

Muhannad

Rename column name & column enum variant#

[#209] Rename the column name and enum variant of a model attribute, especially helpful when the column name is a Rust keyword.

mod my_entity {    use sea_orm::entity::prelude::*;
    #[derive(Clone, Debug, PartialEq, DeriveEntityModel)]    #[sea_orm(table_name = "my_entity")]    pub struct Model {        #[sea_orm(primary_key, enum_name = "IdentityColumn", column_name = "id")]        pub id: i32,        #[sea_orm(column_name = "type")]        pub type_: String,    }
    //...}
assert_eq!(my_entity::Column::IdentityColumn.to_string().as_str(), "id");assert_eq!(my_entity::Column::Type.to_string().as_str(), "type");

Contributed by:

Billy Chan

not on a condition tree#

[#145] Build a complex condition tree with Condition.

use sea_orm::{entity::*, query::*, tests_cfg::cake, sea_query::Expr, DbBackend};
assert_eq!(    cake::Entity::find()        .filter(            Condition::all()                .add(                    Condition::all()                        .not()                        .add(Expr::val(1).eq(1))                        .add(Expr::val(2).eq(2))                )                .add(                    Condition::any()                        .add(Expr::val(3).eq(3))                        .add(Expr::val(4).eq(4))                )        )        .build(DbBackend::Postgres)        .to_string(),    r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE (NOT (1 = 1 AND 2 = 2)) AND (3 = 3 OR 4 = 4)"#);

Contributed by:

nitnelave
6xzo

Community#

SeaQL is a community driven project. We welcome you to participate, contribute and together build for Rust's future.

Here is the roadmap for SeaORM 0.3.x.