8000 Select three by tyt2y3 · Pull Request #2518 · SeaQL/sea-orm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Select three #2518

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

Merged
merged 3 commits into from
Mar 2, 2025
Merged

Select three #2518

merged 3 commits into from
Mar 2, 2025

Conversation

tyt2y3
Copy link
Member
@tyt2y3 tyt2y3 commented Mar 2, 2025

No description provided.

@tyt2y3 tyt2y3 merged commit 455fe64 into master Mar 2, 2025
36 checks passed
@tyt2y3 tyt2y3 deleted the select-three branch March 2, 2025 21:18
Copy link
github-actions bot commented Mar 3, 2025

🎉 Released In 1.1.7 🎉

Thank you everyone for the contribution!
This feature is now available in the latest release. Now is a good time to upgrade!
Your participation is what makes us unique; your adoption is what drives us forward.
You can support SeaQL 🌊 by starring our repos, sharing our libraries and becoming a sponsor ⭐.

@cnwzhu
Copy link
cnwzhu commented Mar 11, 2025

是否可以通过宏定义实现SelectNine

macro_rules! generate_select_structs {
    ($name:ident, $($generics:ident),+) => {
        /// Defines a structure to perform a SELECT operation on two Models
        #[derive(Clone, Debug)]
        pub struct $name<$($generics),*>
        where
            $($generics: EntityTrait),*
        {
            pub(crate) query: SelectStatement,
            pub(crate) entity: PhantomData<($($generics),*)>,
        }
    };

}

// Rust 宏系统不支持 `concat_idents!` 直接在 `macro_rules!` 内使用,
// 这里使用手动展开
generate_select_structs!(SelectTwo, E, F);
generate_select_structs!(SelectThree, E, F, G);
generate_select_structs!(SelectFour, E, F, G, H);
generate_select_structs!(SelectFive, E, F, G, H, I);
generate_select_structs!(SelectSix, E, F, G, H, I, J);
generate_select_structs!(SelectSeven, E, F, G, H, I, J, K);
generate_select_structs!(SelectEight, E, F, G, H, I, J, K, L);
generate_select_structs!(SelectNine, E, F, G, H, I, J, K, L, M);


macro_rules! re_impl_query_trait {
    ($name:ident, $($generics:ident),+) => {
        impl<$($generics),*> QueryTrait for $name<$($generics),*>
        where
            $($generics: EntityTrait),*
        {
            type QueryStatement = SelectStatement;

            fn query(&mut self) -> &mut Self::QueryStatement {
                &mut self.query
            }

            fn as_query(&self) -> &Self::QueryStatement {
                &self.query
            }

            fn into_query(self) -> Self::QueryStatement {
                self.query
            }
        }
    };
}

// 生成 SelectOne ~ SelectNine
re_impl_query_trait!(SelectThree, E, F, G);
re_impl_query_trait!(SelectFour, E, F, G, H);
re_impl_query_trait!(SelectFive, E, F, G, H, I);
re_impl_query_trait!(SelectSix, E, F, G, H, I, J);
re_impl_query_trait!(SelectSeven, E, F, G, H, I, J, K);
re_impl_query_trait!(SelectEight, E, F, G, H, I, J, K, L);
re_impl_query_trait!(SelectNine, E, F, G, H, I, J, K, L, M);

This was referenced Apr 1, 2025
hjarraya pushed a commit to sambaclab/sea-orm that referenced this pull request Apr 29, 2025
* SelectThree

* Tests

* More tests
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.

2 participants
0