qraft-core 0.1.2

Core type system, query model, decoding, and SQL lowering primitives for qraft.
Documentation
//! Grouping helpers for `group by`.

use crate::{
    count_idents,
    expression::Expression,
    impl_for_all_tuples,
    lower::{Instructions, LowerCtx},
};

/// Lowers one or more grouping expressions.
pub trait LowerGroupBy {
    /// Appends the grouping node or nodes to the lowering context.
    fn lower_group_by(self, ctx: &mut LowerCtx);
}

impl<E> LowerGroupBy for E
where
    E: Expression,
{
    fn lower_group_by(self, ctx: &mut LowerCtx) {
        self.lower(ctx);
    }
}

macro_rules! impl_groupby_macro {
    ($($T:ident),+) => {
        impl<$($T,)+> LowerGroupBy for ($($T,)+)
        where
            $($T: LowerGroupBy,)+
        {
            fn lower_group_by(self, ctx: &mut LowerCtx) {
                #[allow(non_snake_case)]
                let ($($T,)+) = self;
                $(
                    $T.lower_group_by(ctx);
                )+
                let count = count_idents!($($T,)+);
                ctx.instrs.push_seperated(count);
            }
        }
    };
}

impl_for_all_tuples!(impl_groupby_macro);