sea-orm icon indicating copy to clipboard operation
sea-orm copied to clipboard

default_expr method not found in `sea_orm::ColumnDef`

Open TKFRvisionOfficial opened this issue 2 years ago • 2 comments

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 avatar Jun 27 '22 13:06 TKFRvisionOfficial

@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.

ikrivosheev avatar Jul 04 '22 07:07 ikrivosheev

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.

billy1624 avatar Jul 04 '22 07:07 billy1624

I think sea-query now supports it, so it should be doable to add macro support in sea-orm

tyt2y3 avatar Nov 06 '22 13:11 tyt2y3

@billy1624 What I exactly need to do in this?

dotdot0 avatar Nov 11 '22 10:11 dotdot0

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 avatar Nov 11 '22 11:11 billy1624

@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>,
}

dotdot0 avatar Nov 12 '22 05:11 dotdot0

Correct!

billy1624 avatar Nov 15 '22 09:11 billy1624

Hey! @billy1624 I couldn't get my head around the macros part can you please help?

dotdot0 avatar Nov 27 '22 16:11 dotdot0

@pratushrai0309 are you still working on this? Otherwise, I'd like to have a go at this one. :)

czzrr avatar Jan 21 '23 08:01 czzrr

@pratushrai0309 are you still working on this? Otherwise, I'd like to have a go at this one. :)

Yeah! Go for it

dotdot0 avatar Jan 21 '23 08:01 dotdot0

@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?

czzrr avatar Jan 22 '23 21:01 czzrr