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

support type alias #77

Closed
huang12zheng opened this issue Oct 15, 2022 · 1 comment · Fixed by #97
Closed

support type alias #77

huang12zheng opened this issue Oct 15, 2022 · 1 comment · Fixed by #97

Comments

@huang12zheng
Copy link

huang12zheng commented Oct 15, 2022

Motivation

I want to def some native type with alias name.

type FirstName = String;
type LastName = String;
type ActorId = u32;

But, it get a error,

seaography::macros::Filter,
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `sea_orm_active_enums` in `entities` 

Proposed Solutions

source from

let filter_item = if default_filters.contains(&type_literal.as_str())
                || type_literal.starts_with("Vec")
            {
                quote! {
                    seaography::TypeFilter<#ty>
                }
            } else {
                let ident = format_ident!("{}EnumFilter", type_literal);
                quote! {
                    crate::entities::sea_orm_active_enums::#ident
                }
            };
  1. It may need to check whether the identifier is an enum

  2. Generate a schema that uses ident directly

Additional Information

maybe the same as #76

use sea_orm::entity::prelude::*;

#[derive(
    Clone,
    Debug,
    PartialEq,
    DeriveEntityModel,
    async_graphql::SimpleObject,
    seaography::macros::Filter, // could not find `sea_orm_active_enums` in `entities`
    // pub struct Filter {
    //     pub or: Option<Vec<Box<Filter>>>,
    //     pub and: Option<Vec<Box<Filter>>>,
    //     actor_id: Option<crate::entities::sea_orm_active_enums::ActorIdEnumFilter>,
    //     first_name: Option<crate::entities::sea_orm_active_enums::FirstNameEnumFilter>,
    //     last_name: Option<crate::entities::sea_orm_active_enums::LastNameEnumFilter>,
    //     last_update: Option<seaography::TypeFilter<DateTimeUtc>>,
    // }
)]
#[sea_orm(table_name = "actor")]
#[graphql(complex)]
#[graphql(name = "Actor")]
// pub struct Model {
//     #[sea_orm(primary_key)]
//     pub actor_id: i32,
//     pub first_name: String,
//     pub last_name: String,
//     pub last_update: DateTimeUtc,
// }
pub struct Model {
    #[sea_orm(primary_key)]
    pub actor_id: ActorId,
    pub first_name: FirstName,
    pub last_name: LastName,
    pub last_update: DateTimeUtc,
}

type FirstName = String;
type LastName = String;
type ActorId = u32;

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation, seaography::macros::RelationsCompact)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}
huang12zheng pushed a commit to huang12zheng/seaography that referenced this issue Oct 15, 2022
@huang12zheng huang12zheng mentioned this issue Oct 15, 2022
3 tasks
@billy1624
Copy link
Member

Hey @huang12zheng, sorry for the delay and thanks for the report!!

Actually, I think this proposal can solve this issue. Which is more generic and foolproof:

@billy1624 billy1624 moved this to Triage in SeaQL Dev Tracker Nov 3, 2022
This was linked to pull requests Nov 11, 2022
@billy1624 billy1624 moved this from Triage to Done in SeaQL Dev Tracker Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
2 participants