Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default_expr method not found in sea_orm::ColumnDef #826

Closed
TKFRvisionOfficial opened this issue Jun 27, 2022 · 11 comments · Fixed by #1474
Closed

default_expr method not found in sea_orm::ColumnDef #826

TKFRvisionOfficial opened this issue Jun 27, 2022 · 11 comments · Fixed by #1474
Labels
good first issue Good for newcomers

Comments

@TKFRvisionOfficial
Copy link

TKFRvisionOfficial commented Jun 27, 2022

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()")
@ikrivosheev
Copy link
Member

@TKFRvisionOfficial hello! Thank you, this is strange, because sea-query has an issue: SeaQL/sea-query#347 I am working on it, but I need more time.

@billy1624
Copy link
Member

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 billy1624 moved this to Triage in SeaQL Dev Tracker Jul 4, 2022
@billy1624 billy1624 moved this from Triage to Next Up in SeaQL Dev Tracker Jul 4, 2022
@tyt2y3
Copy link
Member

tyt2y3 commented Nov 6, 2022

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

@dotdot0
Copy link

dotdot0 commented Nov 11, 2022

@billy1624 What I exactly need to do in this?

@billy1624
Copy link
Member

Update ColumnDef to hold Option<sea_query::SimpleExpr> instead of Option<sea_query::Value>.

Then, update the macros:

if let Some(default_value) = default_value {
match_row = quote! { #match_row.default_value(#default_value) };
}

@dotdot0
Copy link

dotdot0 commented Nov 12, 2022

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

@billy1624
Copy link
Member

Correct!

@dotdot0
Copy link

dotdot0 commented Nov 27, 2022

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

@billy1624 billy1624 moved this from Next Up to Triage in SeaQL Dev Tracker Jan 13, 2023
@czzrr
Copy link

czzrr commented Jan 21, 2023

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

@dotdot0
Copy link

dotdot0 commented Jan 21, 2023

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

Yeah! Go for it

@czzrr
Copy link

czzrr commented Jan 22, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

6 participants