#[macro_export]
macro_rules! expr {
    // expr!(table.c.column)
    ($table:ident.c.$column:ident) => {
        $crate::query::Q::col($table, $table.c.$column)
    };
    // expr!("NOW()")
    ($template:literal) => {
        $crate::query::Q::fill($template, vec![])
    };
    // expr!("LOWER(?)", expr1)
    ($template:literal, $($arg:expr),+ $(,)?) => {
        $crate::query::Q::fill($template, vec![$($arg,)+])
    };
    // expr!([val])
    ([$val:expr]) => {
        $crate::query::Q::val($val)
    };
    // expr!(refer)
    ($refer:expr) => {
        $crate::query::Q::refer($refer)
    };
}

// Ideally, we call the `expr!` macro inside macros too, but Rust doesn't forward matched fragments well:
// https://doc.rust-lang.org/nightly/reference/macros-by-example.html#forwarding-a-matched-fragment

#[macro_export]
macro_rules! op {
    // op!(table.c.coloumn, "IS NULL")
    ($table:ident.c.$column:ident, $op:literal) => {
        $crate::query::Q::post_op($crate::query::Q::col($table, $table.c.$column), $op)
    };

    // op!(table.c.column, "op", table.c.column)
    ($tableL:ident.c.$columnL:ident, $op:literal, $tableR:ident.c.$columnR:ident) => {
        $crate::query::Q::op(
            $crate::query::Q::col($tableL, $tableL.c.$columnL),
            $op,
            $crate::query::Q::col($tableR, $tableR.c.$columnR),
        )
    };
    // op!(table.c.column, "op", [val])
    ($table:ident.c.$column:ident, $op:literal, [$val:expr]) => {
        $crate::query::Q::op(
            $crate::query::Q::col($table, $table.c.$column),
            $op,
            $crate::query::Q::val($val),
        )
    };
    // op!(table.c.column, "op", refer)
    ($table:ident.c.$column:ident, $op:literal, $refer:expr) => {
        $crate::query::Q::op(
            $crate::query::Q::col($table, $table.c.$column),
            $op,
            $crate::query::Q::refer($refer),
        )
    };
}
