qraft-core 0.1.2

Core type system, query model, decoding, and SQL lowering primitives for qraft.
Documentation
use crate::{
    LowerCompatible, NullOf, PredicateType, TernaryType,
    expression::Expression,
    lower::{Instructions, LowerCtx},
    ty::Nullability,
};

#[derive(Debug)]
pub struct Between<E: Expression, L, R> {
    pub(crate) negated: bool,
    pub(crate) lhs: E,
    pub(crate) low: L,
    pub(crate) high: R,
}

#[qraft_expression_macro::as_expression]
impl<E, L, R> Expression for Between<E, L, R>
where
    E: Expression,
    E::Type: Nullability,
    L: LowerCompatible<E::Type>,
    R: LowerCompatible<E::Type>,
    TernaryType<NullOf<E::Type>, NullOf<E::Type>, NullOf<E::Type>>: PredicateType,
{
    type Type =
        <TernaryType<NullOf<E::Type>, NullOf<E::Type>, NullOf<E::Type>> as PredicateType>::Output;

    fn lower(&self, ctx: &mut LowerCtx) -> usize {
        let lhs = self.lhs.lower(ctx);
        let low = self.low.lower_compatible(ctx);
        let high = self.high.lower_compatible(ctx);
        ctx.instrs.push_between(self.negated, lhs, low, high);
        lhs + low + high + 1
    }
}