database: postgres
Enum:
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "test_status")]
pub enum TestStatus {
#[sea_orm(string_value = "new")]
New,
#[sea_orm(string_value = "processing")]
Processing,
}
Model:
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "test")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i64,
pub status: Status,
pub created_at: DateTime,
}
Query:
let select_query = Query::select()
.column(test::Column::Id)
.from(test::Entity)
.and_where(test::Column::Status.eq(TestStatus::New))
.limit(1)
.lock_with_behavior(LockType::Update, LockBehavior::SkipLocked)
.to_owned();
let update_query = Query::update()
.table(test::Entity)
.value(test::Column::Status, TestStatus::Processing.as_enum())
.and_where(test::Column::Id.in_subquery(select_query))
.returning_all()
.to_owned();
let stmt = db.get_database_backend().build(&update_query);
test::Model::find_by_statement(stmt).one(db).await
Query is executed, but final result is:
Query Error: error occurred while decoding column "status": mismatched types; Rust type `core::option::Option<alloc::string::String>` (as SQL type `TEXT`) is not compatible with SQL type `test_status`
database: postgres
Enum:
Model:
Query:
Query is executed, but final result is: