Skip to content

Instantly share code, notes, and snippets.

@weiznich
Created July 14, 2022 13:18
Show Gist options
  • Save weiznich/8f4b7a19ef9789fe960aee3fbed1c66c to your computer and use it in GitHub Desktop.
Save weiznich/8f4b7a19ef9789fe960aee3fbed1c66c to your computer and use it in GitHub Desktop.
#![allow(warnings)]
pub struct Join<L, R, K> {
left: L,
right: R,
kind: K,
}
pub struct SelectStatement<T> {
table: T,
}
pub trait JoinTo<T> {
type FromClause;
type OnClause;
}
impl<Left, Mid, Right, Kind> JoinTo<Right> for Join<Left, Mid, Kind>
where
Left: JoinTo<Right> + QuerySource,
Mid: QuerySource,
{
type FromClause = <Left as JoinTo<Right>>::FromClause;
type OnClause = Left::OnClause;
}
impl<Right, F> JoinTo<Right> for SelectStatement<F>
where
F: JoinTo<Right>,
{
type FromClause = <F as JoinTo<Right>>::FromClause;
type OnClause = F::OnClause;
}
pub struct Inner;
pub trait QuerySource {
}
pub trait Table: QuerySource + Sized {
}
pub trait InternalJoinDsl<Rhs, Kind, On> {
type Output;
fn join(self, rhs: Rhs, kind: Kind, on: On) -> Self::Output;
}
pub trait AsQuery: Sized {
// type SqlType;
type Query; //: Query<SqlType = Self::SqlType>;
fn as_query(self) -> Self::Query {
todo!()
}
}
impl<T, Rhs, Kind, On> InternalJoinDsl<Rhs, Kind, On> for T
where
T: Table + AsQuery,
T::Query: InternalJoinDsl<Rhs, Kind, On>,
{
type Output = <T::Query as InternalJoinDsl<Rhs, Kind, On>>::Output;
fn join(self, rhs: Rhs, kind: Kind, on: On) -> Self::Output {
todo!()
//self.as_query().join(rhs, kind, on)
}
}
impl<F, Rhs, Kind, On> InternalJoinDsl<Rhs, Kind, On> for SelectStatement<F> {
type Output = SelectStatement<Join<F, Rhs, Kind>>;
fn join(self, rhs: Rhs, kind: Kind, on: On) -> Self::Output {
todo!()
//self.as_query().join(rhs, kind, on)
}
}
pub trait JoinWithImplicitOnClause<Rhs, Kind> {
type Output;
fn join_with_implicit_on_clause(self, rhs: Rhs, kind: Kind) -> Self::Output;
}
impl<Lhs, Rhs, Kind> JoinWithImplicitOnClause<Rhs, Kind> for Lhs
where
Lhs: JoinTo<Rhs>,
Lhs: InternalJoinDsl<<Lhs as JoinTo<Rhs>>::FromClause, Kind, <Lhs as JoinTo<Rhs>>::OnClause>,
{
type Output = <Lhs as InternalJoinDsl<Lhs::FromClause, Kind, Lhs::OnClause>>::Output;
fn join_with_implicit_on_clause(self, rhs: Rhs, kind: Kind) -> Self::Output {
// let (from, on) = Lhs::join_target(rhs);
// self.join(from, kind, on)
todo!()
}
}
trait QueryDsl: Sized {
fn inner_join<Rhs>(self, rhs: Rhs) -> <Self as JoinWithImplicitOnClause<Rhs, Inner>>::Output
where
Self: JoinWithImplicitOnClause<Rhs, Inner>,
{
self.join_with_implicit_on_clause(rhs, Inner)
}
}
impl<T> QueryDsl for T where T: Table {}
pub mod schema {
pub mod some_table_1 {
pub struct table;
impl crate::Table for table {}
impl crate::QuerySource for table {}
impl crate::AsQuery for table {
type Query = crate::SelectStatement<Self>;
}
impl<L, R, K> crate::JoinTo<crate::Join<L, R, K>> for table
where
crate::Join<L, R, K>: crate::JoinTo<table>,
{
type FromClause = <crate::Join<L, R, K> as crate::JoinTo<table>>::FromClause;
type OnClause = <crate::Join<L, R, K> as crate::JoinTo<table>>::OnClause;
}
impl<F> crate::JoinTo<crate::SelectStatement<F>> for table
where
table: crate::JoinTo<F>,
{
type FromClause = <table as crate::JoinTo<F>>::FromClause;
type OnClause = <table as crate::JoinTo<F>>::OnClause;
}
}
pub mod some_table_2 {
pub struct table;
impl crate::Table for table {}
impl crate::QuerySource for table {}
impl crate::AsQuery for table {
type Query = crate::SelectStatement<Self>;
}
impl<L, R, K> crate::JoinTo<crate::Join<L, R, K>> for table
where
crate::Join<L, R, K>: crate::JoinTo<table>,
{
type FromClause = <crate::Join<L, R, K> as crate::JoinTo<table>>::FromClause;
type OnClause = <crate::Join<L, R, K> as crate::JoinTo<table>>::OnClause;
}
impl<F> crate::JoinTo<crate::SelectStatement<F>> for table
where
table: crate::JoinTo<F>,
{
type FromClause = <table as crate::JoinTo<F>>::FromClause;
type OnClause = <table as crate::JoinTo<F>>::OnClause;
}
}
pub mod some_table_3 {
pub struct table;
impl crate::Table for table {}
impl crate::QuerySource for table {}
impl crate::AsQuery for table {
type Query = crate::SelectStatement<Self>;
}
impl<L, R, K> crate::JoinTo<crate::Join<L, R, K>> for table
where
crate::Join<L, R, K>: crate::JoinTo<table>,
{
type FromClause = <crate::Join<L, R, K> as crate::JoinTo<table>>::FromClause;
type OnClause = <crate::Join<L, R, K> as crate::JoinTo<table>>::OnClause;
}
impl<F> crate::JoinTo<crate::SelectStatement<F>> for table
where
table: crate::JoinTo<F>,
{
type FromClause = <table as crate::JoinTo<F>>::FromClause;
type OnClause = <table as crate::JoinTo<F>>::OnClause;
}
}
pub mod some_table_4 {
pub struct table;
impl crate::Table for table {}
impl crate::QuerySource for table {}
impl crate::AsQuery for table {
type Query = crate::SelectStatement<Self>;
}
impl<L, R, K> crate::JoinTo<crate::Join<L, R, K>> for table
where
crate::Join<L, R, K>: crate::JoinTo<table>,
{
type FromClause = <crate::Join<L, R, K> as crate::JoinTo<table>>::FromClause;
type OnClause = <crate::Join<L, R, K> as crate::JoinTo<table>>::OnClause;
}
impl<F> crate::JoinTo<crate::SelectStatement<F>> for table
where
table: crate::JoinTo<F>,
{
type FromClause = <table as crate::JoinTo<F>>::FromClause;
type OnClause = <table as crate::JoinTo<F>>::OnClause;
}
}
pub mod some_table_5 {
pub struct table;
impl crate::Table for table {}
impl crate::QuerySource for table {}
impl crate::AsQuery for table {
type Query = crate::SelectStatement<Self>;
}
impl<L, R, K> crate::JoinTo<crate::Join<L, R, K>> for table
where
crate::Join<L, R, K>: crate::JoinTo<table>,
{
type FromClause = <crate::Join<L, R, K> as crate::JoinTo<table>>::FromClause;
type OnClause = <crate::Join<L, R, K> as crate::JoinTo<table>>::OnClause;
}
impl<F> crate::JoinTo<crate::SelectStatement<F>> for table
where
table: crate::JoinTo<F>,
{
type FromClause = <table as crate::JoinTo<F>>::FromClause;
type OnClause = <table as crate::JoinTo<F>>::OnClause;
}
}
pub mod some_table_6 {
pub struct table;
impl crate::Table for table {}
impl crate::QuerySource for table {}
impl crate::AsQuery for table {
type Query = crate::SelectStatement<Self>;
}
impl<L, R, K> crate::JoinTo<crate::Join<L, R, K>> for table
where
crate::Join<L, R, K>: crate::JoinTo<table>,
{
type FromClause = <crate::Join<L, R, K> as crate::JoinTo<table>>::FromClause;
type OnClause = <crate::Join<L, R, K> as crate::JoinTo<table>>::OnClause;
}
impl<F> crate::JoinTo<crate::SelectStatement<F>> for table
where
table: crate::JoinTo<F>,
{
type FromClause = <table as crate::JoinTo<F>>::FromClause;
type OnClause = <table as crate::JoinTo<F>>::OnClause;
}
}
pub mod some_table_7 {
pub struct table;
impl crate::Table for table {}
impl crate::QuerySource for table {}
impl crate::AsQuery for table {
type Query = crate::SelectStatement<Self>;
}
impl<L, R, K> crate::JoinTo<crate::Join<L, R, K>> for table
where
crate::Join<L, R, K>: crate::JoinTo<table>,
{
type FromClause = <crate::Join<L, R, K> as crate::JoinTo<table>>::FromClause;
type OnClause = <crate::Join<L, R, K> as crate::JoinTo<table>>::OnClause;
}
impl<F> crate::JoinTo<crate::SelectStatement<F>> for table
where
table: crate::JoinTo<F>,
{
type FromClause = <table as crate::JoinTo<F>>::FromClause;
type OnClause = <table as crate::JoinTo<F>>::OnClause;
}
}
impl crate::JoinTo<some_table_1::table> for some_table_2::table {
type FromClause = some_table_1::table;
type OnClause = ();
}
impl crate::JoinTo<some_table_2::table> for some_table_1::table {
type FromClause = some_table_2::table;
type OnClause = ();
}
impl crate::JoinTo<some_table_3::table> for some_table_2::table {
type FromClause = some_table_3::table;
type OnClause = ();
}
impl crate::JoinTo<some_table_2::table> for some_table_3::table {
type FromClause = some_table_2::table;
type OnClause = ();
}
impl crate::JoinTo<some_table_3::table> for some_table_4::table {
type FromClause = some_table_3::table;
type OnClause = ();
}
impl crate::JoinTo<some_table_4::table> for some_table_3::table {
type FromClause = some_table_4::table;
type OnClause = ();
}
impl crate::JoinTo<some_table_5::table> for some_table_4::table {
type FromClause = some_table_5::table;
type OnClause = ();
}
impl crate::JoinTo<some_table_4::table> for some_table_5::table {
type FromClause = some_table_4::table;
type OnClause = ();
}
impl crate::JoinTo<some_table_6::table> for some_table_5::table {
type FromClause = some_table_6::table;
type OnClause = ();
}
impl crate::JoinTo<some_table_5::table> for some_table_6::table {
type FromClause = some_table_5::table;
type OnClause = ();
}
impl crate::JoinTo<some_table_6::table> for some_table_7::table {
type FromClause = some_table_6::table;
type OnClause = ();
}
impl crate::JoinTo<some_table_7::table> for some_table_6::table {
type FromClause = some_table_7::table;
type OnClause = ();
}
}
fn test_case() {
let q =
schema::some_table_1::table.inner_join(schema::some_table_2::table.inner_join(
schema::some_table_3::table.inner_join(schema::some_table_4::table.inner_join(
schema::some_table_5::table.inner_join(
schema::some_table_6::table.inner_join(schema::some_table_7::table),
),
)),
));
}
fn main() {
println!("Hello, world!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment