Releases: SeaQL/sea-orm
Releases Β· SeaQL/sea-orm
1.1.7
New Features
- Support nested entities in
FromQueryResult
#2508
#[derive(FromQueryResult)]
struct Cake {
id: i32,
name: String,
#[sea_orm(nested)]
bakery: Option<CakeBakery>,
}
#[derive(FromQueryResult)]
struct CakeBakery {
#[sea_orm(from_alias = "bakery_id")]
id: i32,
#[sea_orm(from_alias = "bakery_name")]
title: String,
}
let cake: Cake = cake::Entity::find()
.select_only()
.column(cake::Column::Id)
.column(cake::Column::Name)
.column_as(bakery::Column::Id, "bakery_id")
.column_as(bakery::Column::Name, "bakery_name")
.left_join(bakery::Entity)
.order_by_asc(cake::Column::Id)
.into_model()
.one(&ctx.db)
.await?
.unwrap();
assert_eq!(
cake,
Cake {
id: 1,
name: "Cake".to_string(),
bakery: Some(CakeBakery {
id: 20,
title: "Bakery".to_string(),
})
}
);
- Support nested entities in
DerivePartialModel
#2508
#[derive(DerivePartialModel)] // FromQueryResult is no longer needed
#[sea_orm(entity = "cake::Entity", from_query_result)]
struct Cake {
id: i32,
name: String,
#[sea_orm(nested)]
bakery: Option<Bakery>,
}
#[derive(DerivePartialModel)]
#[sea_orm(entity = "bakery::Entity", from_query_result)]
struct Bakery {
id: i32,
#[sea_orm(from_col = "Name")]
title: String,
}
// same as previous example, but without the custom selects
let cake: Cake = cake::Entity::find()
.left_join(bakery::Entity)
.order_by_asc(cake::Column::Id)
.into_partial_model()
.one(&ctx.db)
.await?
.unwrap();
assert_eq!(
cake,
Cake {
id: 1,
name: "Cake".to_string(),
bakery: Some(CakeBakery {
id: 20,
title: "Bakery".to_string(),
})
}
);
- Derive also
IntoActiveModel
withDerivePartialModel
#2517
#[derive(DerivePartialModel)]
#[sea_orm(entity = "cake::Entity", into_active_model)]
struct Cake {
id: i32,
name: String,
}
assert_eq!(
Cake {
id: 12,
name: "Lemon Drizzle".to_owned(),
}
.into_active_model(),
cake::ActiveModel {
id: Set(12),
name: Set("Lemon Drizzle".to_owned()),
..Default::default()
}
);
- Added
SelectThree
#2518
// Order -> (many) Lineitem -> Cake
let items: Vec<(order::Model, Option<lineitem::Model>, Option<cake::Model>)> =
order::Entity::find()
.find_also_related(lineitem::Entity)
.and_also_related(cake::Entity)
.order_by_asc(order::Column::Id)
.order_by_asc(lineitem::Column::Id)
.all(&ctx.db)
.await?;
Enhancements
- Support complex type path in
DeriveIntoActiveModel
#2517
#[derive(DeriveIntoActiveModel)]
#[sea_orm(active_model = "<fruit::Entity as EntityTrait>::ActiveModel")]
struct Fruit {
cake_id: Option<Option<i32>>,
}
- Added
DatabaseConnection::close_by_ref
#2511
pub async fn close(self) -> Result<(), DbErr> { .. } // existing
pub async fn close_by_ref(&self) -> Result<(), DbErr> { .. } // new
House Keeping
- Cleanup legacy
ActiveValue::Set
#2515
1.1.6
New Features
- Support PgVector (under feature flag
postgres-vector
) #2500
// Model
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "image_model")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: i32,
pub embedding: PgVector,
}
// Schema
sea_query::Table::create()
.table(image_model::Entity.table_ref())
.col(ColumnDef::new(embedding::Column::Id).integer().not_null().primary_key())
.col(ColumnDef::new(embedding::Column::Embedding).vector(None).not_null())
..
// Insert
ActiveModel {
id: NotSet,
embedding: Set(PgVector::from(vec![1., 2., 3.])),
}
.insert(db)
.await?
- Added
Insert::exec_with_returning_keys
&Insert::exec_with_returning_many
(Postgres only)
assert_eq!(
Entity::insert_many([
ActiveModel { id: NotSet, name: Set("two".into()) },
ActiveModel { id: NotSet, name: Set("three".into()) },
])
.exec_with_returning_many(db)
.await
.unwrap(),
[
Model { id: 2, name: "two".into() },
Model { id: 3, name: "three".into() },
]
);
assert_eq!(
cakes_bakers::Entity::insert_many([
cakes_bakers::ActiveModel {
cake_id: Set(1),
baker_id: Set(2),
},
cakes_bakers::ActiveModel {
cake_id: Set(2),
baker_id: Set(1),
},
])
.exec_with_returning_keys(db)
.await
.unwrap(),
[(1, 2), (2, 1)]
);
- Added
DeleteOne::exec_with_returning
&DeleteMany::exec_with_returning
#2432
Enhancements
- Expose underlying row types (e.g.
sqlx::postgres::PgRow
) #2265 - [sea-orm-cli] Added
acquire-timeout
option #2461 - [sea-orm-cli] Added
with-prelude
option #2322 - [sea-orm-cli] Added
impl-active-model-behavior
option #2487
Bug Fixes
- Fixed
seaography::register_active_enums
macro #2475
House keeping
- Remove
futures
crate, replace withfutures-util
#2466
1.1.5
1.1.4
1.1.3
New Features
- [sea-orm-codegen] register seaography entity modules & active enums #2403
pub mod prelude;
pub mod sea_orm_active_enums;
pub mod baker;
pub mod bakery;
pub mod cake;
pub mod cakes_bakers;
pub mod customer;
pub mod lineitem;
pub mod order;
seaography::register_entity_modules!([
baker,
bakery,
cake,
cakes_bakers,
customer,
lineitem,
order,
]);
seaography::register_active_enums!([
sea_orm_active_enums::Tea,
sea_orm_active_enums::Color,
]);
Enhancements
- Insert many allow active models to have different column set #2433
// this previously panics
let apple = cake_filling::ActiveModel {
cake_id: ActiveValue::set(2),
filling_id: ActiveValue::NotSet,
};
let orange = cake_filling::ActiveModel {
cake_id: ActiveValue::NotSet,
filling_id: ActiveValue::set(3),
};
assert_eq!(
Insert::<cake_filling::ActiveModel>::new()
.add_many([apple, orange])
.build(DbBackend::Postgres)
.to_string(),
r#"INSERT INTO "cake_filling" ("cake_id", "filling_id") VALUES (2, NULL), (NULL, 3)"#,
);
- [sea-orm-cli] Added
MIGRATION_DIR
environment variable #2419 - Added
ColumnDef::is_unique
#2401 - Postgres: quote schema in
search_path
#2436
Bug Fixes
- MySQL: fix transaction isolation level not respected when used with access mode #2450
1.1.2
1.1.1
Enhancements
- [sea-orm-macros]
impl From<Model> for ActiveModel
instead ofimpl From<<Entity as sea_orm::EntityTrait>::Model> for ActiveModel
#2349.
Now the following can compile:
use sea_orm::{tests_cfg::cake, Set};
struct Cake {
id: i32,
name: String,
}
impl From<Cake> for cake::ActiveModel {
fn from(value: Cake) -> Self {
Self {
id: Set(value.id),
name: Set(value.name),
}
}
}
1.1.0
Enhancements
- [sea-orm-macros] Call
EnumIter::get
using fully qualified syntax #2321 - Construct
DatabaseConnection
directly fromsqlx::PgPool
,sqlx::SqlitePool
andsqlx::MySqlPool
#2348 - [sea-orm-migration] Add
pk_uuid
schema helper #2329 - [sea-orm-migration] Allow
custom
andcustom_null
schema helper to take column name and alias of differentIntoIden
types #2326 - Add
ColumnDef::get_column_default
getter #2387
Upgrades
- Upgrade
sqlx
to0.8.2
#2305, #2371 - Upgrade
bigdecimal
to0.4
#2305 - Upgrade
sea-query
to0.32.0-rc
#2305 - Upgrade
sea-query-binder
to0.7.0-rc
#2305 - Upgrade
sea-schema
to0.16.0-rc
#2305 - Upgrade
ouroboros
to0.18
#2353
House keeping
1.1.0-rc.3
Enhancements
- Add
ColumnDef::get_column_default
getter #2387
1.1.0-rc.2
Enhancements
- [sea-orm-macros] Call
EnumIter::get
using fully qualified syntax #2321 - Construct
DatabaseConnection
directly fromsqlx::PgPool
,sqlx::SqlitePool
andsqlx::MySqlPool
#2348 - [sea-orm-migration] Add
pk_uuid
schema helper #2329 - [sea-orm-migration] Allow
custom
andcustom_null
schema helper to take column name and alias of differentIntoIden
types #2326