Skip to main content

What's new in SeaORM 0.12.x

Β· 7 min read
SeaQL Team
SeaORM 0.12 Banner

It had been a while since the initial SeaORM 0.12 release. This blog post summarizes the new features and enhancements introduced in SeaORM 0.12.2 through 0.12.12!

Celebrating 2M downloads on crates.io πŸ“¦β€‹

We've just reached the milestone of 2,000,000 all time downloads on crates.io. It's a testament to SeaORM's adoption in professional use. Thank you to all our users for your trust and for being a part of our community.

New Features​

Entity format update​

  • #1898 Add support for root JSON arrays (requires the json-array / postgres-array feature)! It involved an intricate type system refactor to work around the orphan rule.
#[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,
}
  • #2009 Added comment attribute for Entity; create_table_from_entity now supports comment on MySQL
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "applog", comment = "app logs")]
pub struct Model {
#[sea_orm(primary_key, comment = "ID")]
pub id: i32,
#[sea_orm(comment = "action")]
pub action: String,
pub json: Json,
pub created_at: DateTimeWithTimeZone,
}

Cursor paginator improvements​

  • #2037 Added descending order to Cursor:
// (default behaviour) Before 5 ASC, i.e. id < 5

let mut cursor = Entity::find().cursor_by(Column::Id);
cursor.before(5);

assert_eq!(
cursor.first(4).all(db).await?,
[
Model { id: 1 },
Model { id: 2 },
Model { id: 3 },
Model { id: 4 },
]
);

// (new API) After 5 DESC, i.e. id < 5

let mut cursor = Entity::find().cursor_by(Column::Id);
cursor.after(5).desc();

assert_eq!(
cursor.first(4).all(db).await?,
[
Model { id: 4 },
Model { id: 3 },
Model { id: 2 },
Model { id: 1 },
]
);
  • #1826 Added cursor support to SelectTwo:
// Join with linked relation; cursor by first table's id

cake::Entity::find()
.find_also_linked(entity_linked::CakeToFillingVendor)
.cursor_by(cake::Column::Id)
.before(10)
.first(2)
.all(&db)
.await?

// Join with relation; cursor by the 2nd table's id

cake::Entity::find()
.find_also_related(Fruit)
.cursor_by_other(fruit::Column::Id)
.before(10)
.first(2)
.all(&db)
.await?

Added "proxy" to database backend​

#1881, #2000 Added "proxy" to database backend (requires feature flag proxy).

It enables the possibility of using SeaORM on edge / client-side! See the GlueSQL demo for an example.

Enhancements​

  • #1954 [sea-orm-macro] Added #[sea_orm(skip)] to FromQueryResult derive macro
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, FromQueryResult)]
pub struct PublicUser {
pub id: i64,
pub name: String,
#[serde(skip_serializing_if = "Vec::is_empty")]
#[sea_orm(skip)]
pub something: Something,
}
  • #1598 [sea-orm-macro] Added support for Postgres arrays in FromQueryResult impl of JsonValue
// existing API:

assert_eq!(
Entity::find_by_id(1).one(db).await?,
Some(Model {
id: 1,
name: "Collection 1".into(),
integers: vec![1, 2, 3],
teas: vec![Tea::BreakfastTea],
colors: vec![Color::Black],
})
);

// new API:

assert_eq!(
Entity::find_by_id(1).into_json().one(db).await?,
Some(json!({
"id": 1,
"name": "Collection 1",
"integers": [1, 2, 3],
"teas": ["BreakfastTea"],
"colors": [0],
}))
);
  • #1828 [sea-orm-migration] Check if an index exists
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// ...

// Make sure the index haven't been created
assert!(!manager.has_index("cake", "cake_name_index").await?);

manager
.create_index(
Index::create()
.name("cake_name_index")
.table(Cake::Table)
.col(Cake::Name)
.to_owned(),
)
.await?;

Ok(())
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// ...
}
}
  • #2030 Improve query performance of Paginator's COUNT query
  • #2055 Added SQLx slow statements logging to ConnectOptions
  • #1867 Added QuerySelect::lock_with_behavior
  • #2002 Cast enums in is_in and is_not_in
  • #1999 Add source annotations to errors
  • #1960 Implement StatementBuilder for sea_query::WithQuery
  • #1979 Added method expr_as_ that accepts self
  • #1868 Loader: use ValueTuple as hash key
  • #1934 [sea-orm-cli] Added --enum-extra-derives
  • #1952 [sea-orm-cli] Added --enum-extra-attributes
  • #1693 [sea-orm-cli] Support generation of related entity with composite foreign key

Bug fixes​

  • #1855, #2054 [sea-orm-macro] Qualify types in DeriveValueType macro
  • #1953 [sea-orm-cli] Fix duplicated active enum use statements on generated entities
  • #1821 [sea-orm-cli] Fix entity generation for non-alphanumeric enum variants
  • #2071 [sea-orm-cli] Fix entity generation for relations with composite keys
  • #1800 Fixed find_with_related consolidation logic
  • 5a6acd67 Fixed Loader panic on empty inputs

Upgrades​

  • #1984 Upgraded axum example to 0.7
  • #1858 Upgraded chrono to 0.4.30
  • #1959 Upgraded rocket to 0.5.0
  • Upgraded sea-query to 0.30.5
  • Upgraded sea-schema to 0.14.2
  • Upgraded salvo to 0.50

House Keeping​

  • #2057 Fix clippy warnings on 1.75
  • #1811 Added test cases for find_xxx_related/linked

Release planning​

In the announcement blog post of SeaORM 0.12, we stated we want to reduce the frequency of breaking releases while maintaining the pace for feature updates and enhancements. I am glad to say we've accomplished that!

There are still a few breaking changes planned for the next major release. After some discussions and consideration, we decided that the next major release will be a release candidate for 1.0!

If you feel generous, a small donation will be greatly appreciated, and goes a long way towards sustaining the organization.

A big shout out to our sponsors πŸ˜‡:

Gold Sponsors​

GitHub Sponsors​

Γ‰mile Fugulin
Afonso Barracha
Shane Sveller
Dean Sheather
Marcus Buffett
René Klačan
IceApinan
Jacob Trueb
Kentaro Tanaka
Natsuki Ikeguchi
Marlon Mueller-Soppart
ul
Manfred Lee
KallyDev
Daniel Gallups
Coolpany-SE

Rustacean Sticker Pack πŸ¦€β€‹

The Rustacean Sticker Pack is the perfect way to express your passion for Rust. Our stickers are made with a premium water-resistant vinyl with a unique matte finish. Stick them on your laptop, notebook, or any gadget to show off your love for Rust!

Moreover, all proceeds contributes directly to the ongoing development of SeaQL projects.

Sticker Pack Contents:

  • Logo of SeaQL projects: SeaQL, SeaORM, SeaQuery, Seaography, FireDBG
  • Mascot of SeaQL: Terres the Hermit Crab
  • Mascot of Rust: Ferris the Crab
  • The Rustacean word

Support SeaQL and get a Sticker Pack!

Rustacean Sticker Pack by SeaQL