

#[macro_export]
macro_rules! wheres {
    (
        $(
            $column:literal $op:tt $value:expr        //$column:literal
        ),* $(,)?
    ) => {
        {
            let mut vec = Vec::new();

            $(
                // 重点使用 stringify!($op) 把操作符 =、!= 等转换成字符串，这样就能在 match 中匹配 "=" 了。
                let operator = match stringify!($op) {
                    "=" => $crate::db_common::Operator::Eq,
                    "!=" => $crate::db_common::Operator::Ne,
                    ">" => $crate::db_common::Operator::Gt,
                    ">=" => $crate::db_common::Operator::Gte,
                    "<" => $crate::db_common::Operator::Lt,
                    "<=" => $crate::db_common::Operator::Lte,
                    "in" => $crate::db_common::Operator::In,
                    "like" => $crate::db_common::Operator::Like,
                    "not_in" => $crate::db_common::Operator::NotIn,
                    "btw" => $crate::db_common::Operator::Between,
                    "not_btw" => $crate::db_common::Operator::NotBetween,
                    "is_null" => $crate::db_common::Operator::IsNull,
                    "not_null" => $crate::db_common::Operator::NotNull,
                    _ => panic!("Unknown operator: {}", stringify!($op)),
                };
                vec.push( $crate::db_common::BuildConditionItem {
                    column: $column.to_string(),
                    operator,
                    values: $value.into(),
                    logical: $crate::db_common::Logical::And,
                });
            )*
             vec
        }
    };
}

#[macro_export]
macro_rules! wheres_s {
    (
        $(
            $column:literal $op:tt $value:expr        //$column:literal
        ),* $(,)?
    ) => {
        {
            let mut vec = Vec::new();

            $(
                // 重点使用 stringify!($op) 把操作符 =、!= 等转换成字符串，这样就能在 match 中匹配 "=" 了。
                let operator = match stringify!($op) {
                    "=" => $crate::db_common::Operator::Eq,
                    "!=" => $crate::db_common::Operator::Ne,
                    ">" => $crate::db_common::Operator::Gt,
                    ">=" => $crate::db_common::Operator::Gte,
                    "<" => $crate::db_common::Operator::Lt,
                    "<=" => $crate::db_common::Operator::Lte,
                    "in" => $crate::db_common::Operator::In,
                    "like" => $crate::db_common::Operator::Like,
                    "not_in" => $crate::db_common::Operator::NotIn,
                    "btw" => $crate::db_common::Operator::Between,
                    "not_btw" => $crate::db_common::Operator::NotBetween,
                    "is_null" => $crate::db_common::Operator::IsNull,
                    "not_null" => $crate::db_common::Operator::NotNull,
                    _ => panic!("Unknown operator: {}", stringify!($op)),
                };
                vec.push( $crate::db_common::BuildConditionItem {
                    column: $column.to_string(),
                    operator,
                    values: $value.into(),
                    logical: $crate::db_common::Logical::And,
                });
            )*
             Some(vec)
        }
    };
}


/// orderby!("name",true,"age",false) ture 是降序,false 是升序
#[macro_export]
macro_rules! orderby {
    (
        $(
            $column:expr , $value:expr
        ),* $(,)?
    ) => {
        {

            vec![
                $(
                    $crate::query_build::OrderItem {
                        column: $column.to_string(),
                        direction: $value,
                    }
                ),*
            ]
        }
    };
}

#[macro_export]
macro_rules! bind_params {
    (
        $($bind_value:expr),* $(,)?
    ) => {
         vec![
            $(

                ($bind_value).into()
            ),*
        ]

    };
}

#[macro_export]
macro_rules! update_items {
    (
        $(
            $column:literal $op:tt $value:expr
        ),* $(,)?
    ) => {
        {
            vec![
                $(
                   $crate::query_build::UpdateItem {
                        column: $column.to_string(),
                        value: $value.into(),
                    }
                ),*
            ]
        }
    };
}

#[macro_export]
macro_rules! insert_items {
    (
        $(
            $column:literal $op:tt $value:expr
        ),* $(,)?
    ) => {
        {
             let mut columns = Vec::new();
            $(
                columns.push($column.to_string(),);
            )*

            let mut values = Vec::new();

            $(
                values.push($value.into(),);
            )*

            $crate::query_build::InsertItems {
                columns: columns,
                values:vec![values],
            }
        }
    };
}


