vantage-sql 0.10.0

Vantage extension for SQL databases (Postgres, MySQL, SQLite)
Documentation
//! MySQL-specific operation traits.
//!
//! - `MysqlOperation<T>` — standard comparison ops (eq, gt, lt, etc.) producing
//!   `MysqlCondition`. Generated by `define_sql_operation!` in `condition.rs`.
//! - `MysqlExt` — MySQL-only operators (REGEXP, bitwise AND/OR).

use crate::condition::MysqlCondition;
use crate::define_sql_operation;

define_sql_operation!(
    MysqlOperation,
    MysqlCondition,
    crate::mysql::types::AnyMysqlType
);

use vantage_expressions::{Expression, Expressive, ExpressiveEnum};

use super::types::AnyMysqlType;

type Expr = Expression<AnyMysqlType>;

/// MySQL-specific operations beyond standard comparisons.
pub trait MysqlExt: Expressive<AnyMysqlType> {
    /// `expr REGEXP pattern`
    fn regexp(&self, pattern: impl Expressive<AnyMysqlType>) -> Expr {
        Expression::new(
            "{} REGEXP {}",
            vec![
                ExpressiveEnum::Nested(self.expr()),
                ExpressiveEnum::Nested(pattern.expr()),
            ],
        )
    }

    /// `expr & other` (bitwise AND)
    fn bitand(&self, other: impl Expressive<AnyMysqlType>) -> Expr {
        Expression::new(
            "{} & {}",
            vec![
                ExpressiveEnum::Nested(self.expr()),
                ExpressiveEnum::Nested(other.expr()),
            ],
        )
    }

    /// `expr | other` (bitwise OR)
    fn bitor(&self, other: impl Expressive<AnyMysqlType>) -> Expr {
        Expression::new(
            "{} | {}",
            vec![
                ExpressiveEnum::Nested(self.expr()),
                ExpressiveEnum::Nested(other.expr()),
            ],
        )
    }
}

impl<T: Expressive<AnyMysqlType>> MysqlExt for T {}