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

Entity format #135

Merged
merged 27 commits into from
Sep 10, 2021
Merged

Entity format #135

merged 27 commits into from
Sep 10, 2021

Conversation

tyt2y3
Copy link
Member

@tyt2y3 tyt2y3 commented Sep 7, 2021

@tqwewe
Copy link
Contributor

tqwewe commented Sep 7, 2021

Looking awesome!

We don't want to use the shorter #[sea(...)] instead of #[sea_orm(...)]?

Also, if we wanted this to be more correct (something I even forgot to do), we should add :: before the types. For example impl ::std::default::Default ... and impl ::sea_orm::..., but it's not super important.

Do you think it's worth updating all the macros to take in an DeriveInput parameter and return syn::Result<TokenStream>, and use the struct to store the data?
Now it has a few inconsistencies, and updating it like that would allow a macro_rules for simplifying the lib.rs file.
Eg:

macro_rules! create_derive {
    ($name:ident $(, $( $attrs:ident ),+)?) => {
        paste! {
            #[proc_macro_derive($name, attributes($( $( $attrs ),*)?))]
            pub fn [< $name:snake >](input: TokenStream) -> TokenStream {
                let input = parse_macro_input!(input as DeriveInput);
                derives::[<expand_ $name:snake>](input)
                    .unwrap_or_else(Error::into_compile_error)
                    .into()
            }
        }
    }
}

create_derive!(DeriveEntity, sea);
create_derive!(DerivePrimaryKey);
create_derive!(DeriveColumn);
create_derive!(DeriveCustomColumn);
create_derive!(DeriveModel, sea);
create_derive!(DeriveModelColumn, sea);
create_derive!(DeriveModelPrimaryKey, sea);
create_derive!(DeriveActiveModel);
create_derive!(DeriveActiveModelBehavior);
create_derive!(DeriveRelation, sea);
create_derive!(FromQueryResult);

(the macro above works with the paste crate)

@tyt2y3
Copy link
Member Author

tyt2y3 commented Sep 7, 2021

We don't want to use the shorter #[sea(...)] instead of #[sea_orm(...)]?

I guess the norm is to use the crate's name itself?

Also, if we wanted this to be more correct (something I even forgot to do), we should add :: before the types. For example impl ::std::default::Default ... and impl ::sea_orm::..., but it's not super important.

I think it's fine if someone wants to alias something else as sea_orm.

Do you think it's worth updating all the macros to take in an DeriveInput parameter and return syn::Result<TokenStream>, and use the struct to store the data?

Now it has a few inconsistencies, and updating it like that would allow a macro_rules for simplifying the lib.rs file.

Yes I do think it's a good idea.

@tqwewe
Copy link
Contributor

tqwewe commented Sep 7, 2021

I guess the norm is to use the crate's name itself?

I think it's fine having a shorter version, nothing will conflict with sea. For example, the async-graphql crate uses #[graphql(...)], instead of the full async-graphql.

I think it's fine if someone wants to alias something else as sea_orm.

Sure, it's a very small thing. But I think it's usually a standard thing when writing macros, mainly for ::std::... std library types.

@tyt2y3
Copy link
Member Author

tyt2y3 commented Sep 8, 2021

I hope sea_orm is not too long to be obstructive )
I do agree on the ::std thing, but we actually use create as sea_orm ourselves

use crate as sea_orm;

@tyt2y3 tyt2y3 merged commit eca3949 into master Sep 10, 2021
@tyt2y3 tyt2y3 deleted the entity-format branch September 10, 2021 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants