github SeaQL/sea-orm 0.4.0

latest releases: 1.0.0-rc.4, 1.0.0-rc.3, 0.12.15...
2 years ago

Fixed Issues

  • Disable SQLx query logging #290
  • Code generated by sea-orm-cli cannot pass clippy #296
  • Should return detailed error message for connection failure #310
  • DateTimeWithTimeZone does not implement Serialize and Deserialize #319
  • Support returning clause to avoid database hits #183

Merged PRs

Breaking Changes

  • Refactor paginate() & count() utilities into PaginatorTrait. You can use the paginator as usual but you might need to import PaginatorTrait manually when upgrading from previous version.
    use futures::TryStreamExt;
    use sea_orm::{entity::*, query::*, tests_cfg::cake};
    
    let mut cake_stream = cake::Entity::find()
        .order_by_asc(cake::Column::Id)
        .paginate(db, 50)
        .into_stream();
    
    while let Some(cakes) = cake_stream.try_next().await? {
        // Do something on cakes: Vec<cake::Model>
    }
  • The helper struct Schema converting EntityTrait into different sea-query statement now has to be initialized with DbBackend.
    use sea_orm::{tests_cfg::*, DbBackend, Schema};
    use sea_orm::sea_query::TableCreateStatement;
    
    // 0.3.x
    let _: TableCreateStatement = Schema::create_table_from_entity(cake::Entity);
    
    // 0.4.x
    let schema: Schema = Schema::new(DbBackend::MySql);
    let _: TableCreateStatement = schema.create_table_from_entity(cake::Entity);
  • When performing insert or update operation on ActiveModel against PostgreSQL, RETURNING clause will be used to perform select in a single SQL statement.
    // For PostgreSQL
    cake::ActiveModel {
        name: Set("Apple Pie".to_owned()),
        ..Default::default()
    }
    .insert(&postgres_db)
    .await?;
    
    assert_eq!(
        postgres_db.into_transaction_log(),
        vec![Transaction::from_sql_and_values(
            DbBackend::Postgres,
            r#"INSERT INTO "cake" ("name") VALUES ($1) RETURNING "id", "name""#,
            vec!["Apple Pie".into()]
        )]);
    // For MySQL & SQLite
    cake::ActiveModel {
        name: Set("Apple Pie".to_owned()),
        ..Default::default()
    }
    .insert(&other_db)
    .await?;
    
    assert_eq!(
        other_db.into_transaction_log(),
        vec![
            Transaction::from_sql_and_values(
                DbBackend::MySql,
                r#"INSERT INTO `cake` (`name`) VALUES (?)"#,
                vec!["Apple Pie".into()]
            ),
            Transaction::from_sql_and_values(
                DbBackend::MySql,
                r#"SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`id` = ? LIMIT ?"#,
                vec![15.into(), 1u64.into()]
            )]);

New Contributors

Full Changelog: 0.3.2...0.4.0

Don't miss a new sea-orm release

NewReleases is sending notifications on new releases.