sea-orm
sea-orm copied to clipboard
default_expr method not found in `sea_orm::ColumnDef`
Description
default_expr does not seem to be implemented
Steps to Reproduce
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "stuff")]
pub struct Model {
#[sea_orm(default_expr = "gen_random_uuid()", unique)]
pub cool_uuid: Uuid,
}
Expected Behavior
A uuid should be generated if none specified.
Actual Behavior
3 | #[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
| ^^^^^^^^^^^^^^^^^ method not found in `sea_orm::ColumnDef`
Reproduces How Often
Always
Versions
????????? sea-orm v0.7.1
??? ????????? sea-orm-macros v0.7.0 (proc-macro)
??? ????????? sea-query v0.23.0
??? ??? ????????? sea-query-derive v0.2.0 (proc-macro)
??? ????????? sea-strum v0.23.0
??? ??? ????????? sea-strum_macros v0.23.0 (proc-macro)
Windows 10
Additional Information
(Cargo Expand)
Self::CoolUuid => sea_orm::prelude::ColumnType::Uuid
.def()
.unique()
.default_expr("gen_random_uuid()")
@TKFRvisionOfficial hello! Thank you, this is strange, because sea-query has an issue: https://github.com/SeaQL/sea-query/issues/347 I am working on it, but I need more time.
Hey @TKFRvisionOfficial, sorry for the delay. We will support default_expr
in sea-query
first. Then, we will make the API available on sea-orm
as well.
I think sea-query now supports it, so it should be doable to add macro support in sea-orm
@billy1624 What I exactly need to do in this?
Update ColumnDef
to hold Option<sea_query::SimpleExpr>
instead of Option<sea_query::Value>
.
Then, update the macros:
https://github.com/SeaQL/sea-orm/blob/565cb5e6d0794e5af2ed3910e78a3dedf1d683dd/sea-orm-macros/src/derives/entity_model.rs#L297-L299
@billy1624 I think it was the first part of the task
#[derive(Debug, Clone, PartialEq)]
pub struct ColumnDef {
pub(crate) col_type: ColumnType,
pub(crate) null: bool,
pub(crate) unique: bool,
pub(crate) indexed: bool,
pub(crate) default_value: Option<SimpleExpr>,
}
Correct!
Hey! @billy1624 I couldn't get my head around the macros part can you please help?
@pratushrai0309 are you still working on this? Otherwise, I'd like to have a go at this one. :)
@pratushrai0309 are you still working on this? Otherwise, I'd like to have a go at this one. :)
Yeah! Go for it
@billy1624 Since ColumnDef
implements PartialEq
, changing default_value: Option<Value>
to default_value: Option<SimpleExpr>
would require SimpleExpr
to also implement PartialEq
. What do you suggest for this?
Also, once ColumnDef
holds a SimpleExpr
, would it be enough to introduce a default_expr
method for it, as the macros expand to that method call?