What's new in SeaORM 0.5.0
π We are pleased to release SeaORM 0.5.0 today! Here are some feature highlights π:
Insert and Update Return Modelβ
[#339] As asked and requested by many of our community members. You can now get the refreshed Model after insert or update operations. If you want to mutate the model and save it back to the database you can convert it into ActiveModel with the method into_active_model.
Breaking Changes:
ActiveModel::insertandActiveModel::updatereturnModelinstead ofActiveModel- Method
ActiveModelBehavior::after_savetakesModelas input instead ofActiveModel
// Construct a `ActiveModel`
let active_model = ActiveModel {
name: Set("Classic Vanilla Cake".to_owned()),
..Default::default()
};
// Do insert
let cake: Model = active_model.insert(db).await?;
assert_eq!(
cake,
Model {
id: 1,
name: "Classic Vanilla Cake".to_owned(),
}
);
// Covert `Model` into `ActiveModel`
let mut active_model = cake.into_active_model();
// Change the name of cake
active_model.name = Set("Chocolate Cake".to_owned());
// Do update
let cake: Model = active_model.update(db).await?;
assert_eq!(
cake,
Model {
id: 1,
name: "Chocolate Cake".to_owned(),
}
);
// Do delete
cake.delete(db).await?;
ActiveValue Revampedβ
[#340] The ActiveValue is now defined as an enum instead of a struct. The public API of it remains unchanged, except Unset was deprecated and ActiveValue::NotSet should be used instead.
Breaking Changes:
- Rename method
sea_orm::unchanged_active_value_not_intended_for_public_usetosea_orm::Unchanged - Rename method
ActiveValue::unsettoActiveValue::not_set - Rename method
ActiveValue::is_unsettoActiveValue::is_not_set PartialEqofActiveValuewill also check the equality of state instead of just checking the equality of value
/// Defines a stateful value used in ActiveModel.
pub enum ActiveValue<V>
where
V: Into<Value>,
{
/// A defined [Value] actively being set
Set(V),
/// A defined [Value] remain unchanged
Unchanged(V),
/// An undefined [Value]
NotSet,
}
SeaORM CLI & Codegen Updatesβ
Install latest version of sea-orm-cli:
cargo install sea-orm-cli
Updates related to entity files generation (cargo generate entity):
- [#348] Discovers and defines PostgreSQL enums
- [#386] Supports SQLite database, you can generate entity files from all supported databases including MySQL, PostgreSQL and SQLite
Tracingβ
[#373] You can trace the query executed by SeaORM with debug-print feature enabled and tracing-subscriber up and running.
pub async fn main() {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::DEBUG)
.with_test_writer()
.init();
// ...
}
Contributed by:
Sponsorβ
Our GitHub Sponsor profile is up! If you feel generous, a small donation will be greatly appreciated.
A big shout out to our sponsors π:
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.6.x.
