qraft-core 0.1.2

Core type system, query model, decoding, and SQL lowering primitives for qraft.
Documentation
//! Typed SQL expression nodes and extension traits.

mod bound;
pub use bound::*;

mod r#in;
pub use r#in::*;

mod exists;
pub use exists::*;

mod fn_call;
pub use fn_call::*;

mod like;
pub use like::*;

mod between;
pub use between::*;

mod binary;
pub use binary::*;

mod scalar;
pub use scalar::*;

mod lit;
pub use lit::*;

mod math;
pub use math::*;

mod json;
pub use json::*;

mod temporal;
pub use temporal::*;

mod grouped;
pub use grouped::*;

mod unary;
pub use unary::*;

mod r#as;
pub use r#as::*;

mod column;
pub use column::*;

use crate::{lower::LowerCtx, ty::TypeMeta};

/// Lowers a typed expression into the instruction stream used by the emitter.
pub trait Expression {
    /// SQL type produced by this expression.
    type Type: TypeMeta;

    /// Appends the expression to the lowering context and returns its subtree size.
    fn lower(&self, ctx: &mut LowerCtx) -> usize;
}

impl<E> Expression for &E
where
    E: Expression,
{
    type Type = E::Type;

    fn lower(&self, ctx: &mut LowerCtx) -> usize {
        E::lower(self, ctx)
    }
}

/// Borrow-to-expression conversion used throughout the builder API.
pub trait AsExpression<T: TypeMeta> {
    /// Concrete expression type returned for a borrowed value.
    type Expression<'e>: Expression<Type = T>
    where
        Self: 'e;

    /// Borrows `self` as a typed expression.
    fn as_expression<'e>(&'e self) -> Self::Expression<'e>;
}