Skip to content

SelectThree up to SelectNine #21

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

Closed
tyt2y3 opened this issue Jun 14, 2021 · 8 comments · May be fixed by #2553
Closed

SelectThree up to SelectNine #21

tyt2y3 opened this issue Jun 14, 2021 · 8 comments · May be fixed by #2553

Comments

@tyt2y3
Copy link
Member

tyt2y3 commented Jun 14, 2021

Right now we have a tuple based selector for select one and two. Need to think about how to generalise and support up to arity 9 perhaps?

src/query/combine.rs

@tyt2y3 tyt2y3 changed the title SelectThree up to SelectNine? SelectThree up to SelectNine Jun 14, 2021
@billy1624
Copy link
Member

Use macro to generate each SelectX as follows...?

Repeated for up to 9. With SelectNine without select_also().

#[derive(Clone, Debug)]
pub struct SelectTwo<E, F>
where
    E: EntityTrait,
    F: EntityTrait,
{
    pub(crate) query: SelectStatement,
    pub(crate) entity: PhantomData<(E, F)>,
}

impl<E, F> SelectTwo<E, F>
where
    E: EntityTrait,
    F: EntityTrait,
{
    pub(crate) fn new(query: SelectStatement) -> Self {
        let myself = Self {
            query,
            entity: PhantomData,
        };
        myself.prepare_select()
    }

    fn prepare_select(mut self) -> Self {
        for col in <F::Column as Iterable>::iter() {
            let alias = format!("{}{}", SELECT_B, col.to_string().as_str());
            self.query.expr(SelectExpr {
                expr: col.into_simple_expr(),
                alias: Some(SeaRc::new(Alias::new(&alias))),
            });
        }
        self
    }

    fn apply_alias(mut self, pre: &str) -> Self { ... }

    pub fn select_also<G>(mut self, _: G) -> SelectThree<E, F, G>
    where
        G: EntityTrait,
    {
        self = self.apply_alias(SELECT_C);
        SelectThree::new(self.into_query())
    }
}

macro_rules! impl_trait {
    ( $trait: ident ) => {
        impl<E, F> $trait for SelectTwo<E, F>
        where
            E: EntityTrait,
            F: EntityTrait,
        {
            type QueryStatement = SelectStatement;

            fn query(&mut self) -> &mut SelectStatement {
                &mut self.query
            }
        }
    };
}

impl_trait!(QuerySelect);
impl_trait!(QueryFilter);
impl_trait!(QueryOrder);

@billy1624
Copy link
Member

If we use macro to generate these, will end user be able to infer the type?

i.e. will rust-analyser be able to infer & show the SelectX type?

@tyt2y3
Copy link
Member Author

tyt2y3 commented Jun 15, 2021

We probably will delay this feature post 0.1.0

@billy1624
Copy link
Member

Ok, not a priority

@tyt2y3
Copy link
Member Author

tyt2y3 commented Jul 8, 2021

Close this for now. Re-open when we are decided to work on this again.

@tyt2y3 tyt2y3 closed this as completed Jul 8, 2021
SebastienGllmt pushed a commit to dcSpark/sea-orm that referenced this issue Apr 13, 2022
CI: Clippy, MySQL & Postgres
@guymave
Copy link

guymave commented Mar 30, 2025

why did you close this? :(

@tyt2y3
Copy link
Member Author

tyt2y3 commented Mar 31, 2025

there's a newer discussion thread on this. I couldn't find atm.
But SelectThree has already landed, so potentially we can macro our way to SelectNine

@billy1624
Copy link
Member

billy1624 commented Apr 1, 2025

@billy1624 billy1624 mentioned this issue Apr 1, 2025
1 task
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 a pull request may close this issue.

3 participants