Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions Blog/blog/2026-01-12-sea-orm-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,51 @@ pub struct MyInteger(pub i32);
// only for i8 | i16 | i32 | i64 | u8 | u16 | u32 | u64
```

### Native enum value is now `sea_query::Enum`

[#3043](https://github.com/SeaQL/sea-orm/pull/3043) Native database enums now use `rs_type = "Enum"`, which is also the default when `rs_type` is omitted and what `sea-orm-cli` generates. `ActiveEnum::Value` becomes `sea_query::Enum` instead of `String`, so the value carries the enum type name.

```rust
// old
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "tea")]

// new
#[sea_orm(rs_type = "Enum", db_type = "Enum", enum_name = "tea")]
```

`to_value` now returns a `sea_query::Enum`, and `try_from_value` expects a `&sea_query::Enum`. Use `TryFrom<&str>` to convert from a string:

```rust
// old
let tea = Tea::try_from_value(&string)?;
let s: String = tea.to_value();

// new
let tea = Tea::try_from(string.as_str())?;
let s: String = tea.to_value().value.into_owned();
```

`rs_type = "String"` is still supported if you prefer to keep `String` values.

#### Possible compile errors

```rust
error[E0308]: mismatched types
|
> | Tea::try_from_value(&string)
| ------------------- ^^^^^^^ expected `&Enum`, found `&String`
|
= note: expected reference `&sea_orm::sea_query::Enum`
found reference `&std::string::String`
```

```rust
error[E0308]: mismatched types
|
> | let s: String = tea.to_value();
| ^^^^^^^^^^^^^^ expected `String`, found `Enum`
```

### `execute` -> `execute_raw`

[#2657](https://github.com/SeaQL/sea-orm/pull/2657) Overhauled `ConnectionTrait` API: `execute`, `query_one`, `query_all`, `stream` now takes in SeaQuery statement instead of raw SQL statement, and methods accepting `Statement` has been moved to `*_raw`.
Expand Down
16 changes: 14 additions & 2 deletions SeaORM/docs/04-generate-entity/04-enumeration.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub enum Color {

```rust
#[derive(EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "tea")]
#[sea_orm(rs_type = "Enum", db_type = "Enum", enum_name = "tea")]
pub enum Tea {
#[sea_orm(string_value = "EverydayTea")]
EverydayTea,
Expand All @@ -97,6 +97,18 @@ pub enum Tea {
}
```

With `rs_type = "Enum"` (the default when `rs_type` is omitted, and what `sea-orm-cli` generates), `ActiveEnum::Value` is [`sea_query::Enum`](https://docs.rs/sea-query/1/sea_query/value/struct.Enum.html), which carries the enum type name along with the string value. To convert from and to a string:

```rust
// &str -> Tea
let tea = Tea::try_from("EverydayTea")?;

// Tea -> String
let s: String = tea.to_value().value.into_owned();
```

`rs_type = "String"` is also supported, in which case `ActiveEnum::Value` is `String`.

### MySQL

MySQL enum is just part of the column definition, and cannot be reused for different tables.
Expand Down Expand Up @@ -142,7 +154,7 @@ manager

```rust
#[derive(EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "tea")]
#[sea_orm(rs_type = "Enum", db_type = "Enum", enum_name = "tea")]
pub enum Tea {
#[sea_orm(string_value = "EverydayTea")]
EverydayTea,
Expand Down
4 changes: 2 additions & 2 deletions SeaORM/docs/09-schema-statement/02-create-enum.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub struct Model {
}

#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "tea")]
#[sea_orm(rs_type = "Enum", db_type = "Enum", enum_name = "tea")]
pub enum Tea {
#[sea_orm(string_value = "EverydayTea")]
EverydayTea,
Expand All @@ -121,7 +121,7 @@ pub enum Tea {
}
```

Note the `db_type` and extra `enum_name` attributes.
Note the `rs_type`, `db_type` and extra `enum_name` attributes.

### PostgreSQL

Expand Down