Skip to content

Releases: SeaQL/sea-orm

0.12.9

08 Dec 15:09
Compare
Choose a tag to compare

Enhancements

  • Add source annotations to errors #1999

Upgrades

0.12.8

04 Dec 11:25
Compare
Choose a tag to compare

Enhancements

  • Implement StatementBuilder for sea_query::WithQuery #1960

Upgrades

  • Upgrade axum example to 0.7 #1984

0.12.7

22 Nov 22:50
Compare
Choose a tag to compare

Enhancements

  • Added method expr_as_ that accepts self

Upgrades

0.12.6

13 Nov 18:15
Compare
Choose a tag to compare

New Features

  • Added #[sea_orm(skip)] for FromQueryResult derive macro #1954

Contributors

0.12.5

12 Nov 20:22
Compare
Choose a tag to compare

Bug Fixes

  • [sea-orm-cli] Fix duplicated active enum use statements on generated entities #1953
  • [sea-orm-cli] Added --enum-extra-derives #1934
  • [sea-orm-cli] Added --enum-extra-attributes #1952

Contributors

Full Changelog: 0.12.4...0.12.5

0.12.4

19 Oct 20:03
Compare
Choose a tag to compare

New Features

  • Add support for root JSON arrays #1898
    Now the following works (requires the json-array / postgres-array feature)!
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "json_struct_vec")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i32,
    #[sea_orm(column_type = "Json")]
    pub struct_vec: Vec<JsonColumn>,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, FromJsonQueryResult)]
pub struct JsonColumn {
    pub value: String,
}

Enhancements

  • Loader: use ValueTuple as hash key #1868

Upgrades

0.12.3

22 Sep 17:15
Compare
Choose a tag to compare

New Features

  • [sea-orm-migration] Check if an index exists #1828
  • Added cursor_by to SelectTwo #1826

Enhancements

  • [sea-orm-cli] Support generation of related entity with composite foreign key #1693

Bug Fixes

  • [sea-orm-macro] Fixed DeriveValueType by qualifying QueryResult #1855
  • Fixed Loader panic on empty inputs

Upgrades

  • Upgraded salvo to 0.50
  • Upgraded chrono to 0.4.30 #1858
  • Updated sea-query to 0.30.1
  • Updated sea-schema to 0.14.1

House keeping

  • Added test cases for find_xxx_related/linked #1811

0.12.2

04 Aug 21:40
Compare
Choose a tag to compare

Enhancements

  • Added support for Postgres arrays in FromQueryResult impl of JsonValue #1598

Bug fixes

  • Fixed find_with_related consolidation logic #1800

0.12.1

02 Aug 17:11
Compare
Choose a tag to compare

New Features

  • Added MigratorTrait::migration_table_name() method to configure the name of migration table #1511
#[async_trait::async_trait]
impl MigratorTrait for Migrator {
    // Override the name of migration table
    fn migration_table_name() -> sea_orm::DynIden {
        Alias::new("override_migration_table_name").into_iden()
    }
    ...
}
  • Added option to construct chained AND / OR join on condition #1433
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "cake")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i32,
    pub name: String,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    // By default, it's
    // `JOIN `fruit` ON `cake`.`id` = `fruit`.`cake_id` AND `fruit`.`name` LIKE '%tropical%'`
    #[sea_orm(
        has_many = "super::fruit::Entity",
        on_condition = r#"super::fruit::Column::Name.like("%tropical%")"#
    )]
    TropicalFruit,
    // Or specify `condition_type = "any"` to override it,
    // `JOIN `fruit` ON `cake`.`id` = `fruit`.`cake_id` OR `fruit`.`name` LIKE '%tropical%'`
    #[sea_orm(
        has_many = "super::fruit::Entity",
        on_condition = r#"super::fruit::Column::Name.like("%tropical%")"#
        condition_type = "any",
    )]
    OrTropicalFruit,
}
  • Supports entity with composite primary key of arity 12 #1508
    • Identity supports tuple of DynIden with arity up to 12
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "primary_key_of_12")]
pub struct Model {
    #[sea_orm(primary_key, auto_increment = false)]
    pub id_1: String,
    ...
    #[sea_orm(primary_key, auto_increment = false)]
    pub id_12: bool,
}
  • Added macro DerivePartialModel #1597
#[derive(DerivePartialModel, FromQueryResult)]
#[sea_orm(entity = "Cake")]
struct PartialCake {
    name: String,
    #[sea_orm(
        from_expr = r#"SimpleExpr::FunctionCall(Func::upper(Expr::col((Cake, cake::Column::Name))))"#
    )]
    name_upper: String,
}

assert_eq!(
    cake::Entity::find()
        .into_partial_model::<PartialCake>()
        .into_statement(DbBackend::Sqlite)
        .to_string(),
    r#"SELECT "cake"."name", UPPER("cake"."name") AS "name_upper" FROM "cake""#
);
  • Added DbErr::sql_err() method to convert error into common database errors SqlErr, such as unique constraint or foreign key violation errors. #1707
assert!(matches!(
    cake.into_active_model().insert(db).await
        .expect_err("Insert a row with duplicated primary key")
        .sql_err(),
    Some(SqlErr::UniqueConstraintViolation(_))
));

assert!(matches!(
    fk_cake.insert(db).await
        .expect_err("Insert a row with invalid foreign key")
        .sql_err(),
    Some(SqlErr::ForeignKeyConstraintViolation(_))
));
  • Added Select::find_with_linked, similar to find_with_related: #1728, #1743
fn find_with_related<R>(self, r: R) -> SelectTwoMany<E, R>
    where R: EntityTrait, E: Related<R>;
fn find_with_linked<L, T>(self, l: L) -> SelectTwoMany<E, T>
    where L: Linked<FromEntity = E, ToEntity = T>, T: EntityTrait;

// boths yields `Vec<(E::Model, Vec<F::Model>)>`
  • Added DeriveValueType derive macro for custom wrapper types, implementations of the required traits will be provided, you can customize the column_type and array_type if needed #1720
#[derive(DeriveValueType)]
#[sea_orm(array_type = "Int")]
pub struct Integer(i32);

#[derive(DeriveValueType)]
#[sea_orm(column_type = "Boolean", array_type = "Bool")]
pub struct Boolbean(pub String);

#[derive(DeriveValueType)]
pub struct StringVec(pub Vec<String>);
  • Added DeriveDisplay derive macro to implements std::fmt::Display for enum #1726
#[derive(DeriveDisplay)]
enum DisplayTea {
    EverydayTea,
    #[sea_orm(display_value = "Breakfast Tea")]
    BreakfastTea,
}
assert_eq!(format!("{}", DisplayTea::EverydayTea), "EverydayTea");
assert_eq!(format!("{}", DisplayTea::BreakfastTea), "Breakfast Tea");
  • Added UpdateMany::exec_with_returning() #1677
let models: Vec<Model> = Entity::update_many()
    .col_expr(Column::Values, Expr::expr(..))
    .exec_with_returning(db)
    .await?;
  • Supporting default_expr in DeriveEntityModel #1474
#[derive(DeriveEntityModel)]
#[sea_orm(table_name = "hello")]
pub struct Model {
    #[sea_orm(default_expr = "Expr::current_timestamp()")]
    pub timestamp: DateTimeUtc,
}

assert_eq!(
    Column::Timestamp.def(),
    ColumnType::TimestampWithTimeZone.def()
        .default(Expr::current_timestamp())
);
  • Introduced new ConnAcquireErr #1737
enum DbErr {
    ConnectionAcquire(ConnAcquireErr),
    ..
}

enum ConnAcquireErr {
    Timeout,
    ConnectionClosed,
}

Seaography

Added Seaography integration #1599

  • Added DeriveEntityRelated macro which will implement seaography::RelationBuilder for RelatedEntity enumeration when the seaography feature is enabled

  • Added generation of seaography related information to sea-orm-codegen.

    The RelatedEntity enum is added in entities files by sea-orm-cli when flag seaography is set:

/// SeaORM Entity
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)]
pub enum RelatedEntity {
    #[sea_orm(entity = "super::bakery::Entity")]
    Bakery,
    #[sea_orm(entity = "super::cake_baker::Entity")]
    CakeBaker,
    #[sea_orm(entity = "super::cake::Entity")]
    Cake,
}

Enhancements

  • Supports for partial select of Option<T> model field. A None value will be filled when the select result does not contain the Option<T> field without throwing an error. #1513
  • [sea-orm-cli] the migrate init command will create a .gitignore file when the migration folder reside in a Git repository #1334
  • [sea-orm-cli] Added support for generating migration of space separated name, for example executing sea-orm-cli migrate generate "create accounts table" command will create m20230503_000000_create_accounts_table.rs for you #1570
  • Added Migration::name() and Migration::status() getters for the name and status of sea_orm_migration::Migration #1519
let migrations = Migrator::get_pending_migrations(db).await?;
assert_eq!(migrations.len(), 5);

let migration = migrations.get(0).unwrap();
assert_eq!(migration.name(), "m20220118_000002_create_fruit_table");
assert_eq!(migration.status(), MigrationStatus::Pending);
  • The postgres-array feature will be enabled when sqlx-postgres backend is selected #1565
  • Replace String parameters in API with Into<String> #1439
    • Implements IntoMockRow for any BTreeMap that is indexed by string impl IntoMockRow for BTreeMap<T, Value> where T: Into<String>
    • Converts any string value into ConnectOptions - impl From<T> for ConnectOptions where T: Into<String>
    • Changed the parameter of method ConnectOptions::new(T) where T: Into<String> to takes any string SQL
    • Changed the parameter of method Statement::from_string(DbBackend, T) where T: Into<String> to takes any string SQL
    • Changed the parameter of method Statement::from_sql_and_values(DbBackend, T, I) where I: IntoIterator<Item = Value>, T: Into<String> to takes any string SQL
    • Changed the parameter of method Transaction::from_sql_and_values(DbBackend, T, I) where I: IntoIterator<Item = Value>, T: Into<String> to takes any string SQL
    • Changed the parameter of method ConnectOptions::set_schema_search_path(T) where T: Into<String> to takes any string
    • Changed the parameter of method ColumnTrait::like(), ColumnTrait::not_like(), ColumnTrait::starts_with(), ColumnTrait::ends_with() and ColumnTrait::contains() to takes any string
  • Added sea_query::{DynIden, RcOrArc, SeaRc} to entity prelude #1661
  • Added expr, exprs and expr_as methods to QuerySelect trait #1702
  • Added DatabaseConnection::ping #1627
|db: DatabaseConnection| {
    assert!(db.ping().await.is_ok());
    db.clone().close().await;
    assert!(matches!(db.ping().await, Err(DbErr::ConnectionAcquire)));
}
  • Added TryInsert that does not panic on empty inserts #1708
// now, you can do:
let res = Bakery::insert_many(std::iter::empty())
    .on_empty_do_nothing()
    .exec(db)
    .await;

assert!(matches!(res, Ok(TryInsertResult::Empty)));
  • Insert on conflict do nothing to return Ok #1712
let on = OnConflict::column(Column::Id).do_nothing().to_owned();

// Existing behaviour
let res = Entity::insert_many([..]).on_conflict(on).exec(db).await;
assert!(matches!(res, Err(DbErr::RecordNotInserted)));

// New API; now you can:
let res =
Entity::insert_many([..]).on_conflict(on).do_nothing().exec(db).await;
assert!(matche...
Read more

0.11.3

24 Apr 13:29
Compare
Choose a tag to compare

Enhancements

  • Re-export sea_orm::ConnectionTrait in sea_orm_migration::prelude #1577
  • Support generic structs in FromQueryResult derive macro #1464, #1603
#[derive(FromQueryResult)]
struct GenericTest<T: TryGetable> {
    foo: i32,
    bar: T,
}
trait MyTrait {
    type Item: TryGetable;
}

#[derive(FromQueryResult)]
struct TraitAssociateTypeTest<T>
where
    T: MyTrait,
{
    foo: T::Item,
}

Bug Fixes

  • Fixed #1608 by pinning the version of tracing-subscriber dependency to 0.3.17 #1609