Macro find_many

Source
macro_rules! find_many {
    (connection => $connection:expr,
        model:$model:expr
        $(,match:$model_value:expr)?
        $(,select:{$($select_value:expr),*})?
        $(
            ,case:{
                    $(($($key:expr => $value:expr),*) => ($(ok:$ok:expr),*,else:$else:expr) => $case:expr),*
            }
        )?
        $(,conditions : {
            $(and => {
                $($and_key:expr => $and_value:expr),*
                }
            )?
            $(,)?
            $(
                or => {
                    $($or_key:expr => $or_value:expr),*
                }
            )?
        }
        )?
        $(,)?
        $(
            ,between => {
                $(and => {
                    $($between:expr => {$between_value:expr => $between_value2:expr}),*
                })?
                $(,)?
                $(or => {
                    $($between_or:expr => {$between_value_or:expr => $between_value2_or:expr}),*
                })?
            }
        )?
        $(,)?
        $(
            ,like => {
                $(and => {
                    $($like:expr => $like_value:expr),*
                })?
                $(,)?
                $(or => {
                    $($like_or:expr => $like_value_or:expr),*
                })?
            }
        )?
        $(,inside:
        {
            // (
            $include:expr
                => {
                    match:$include_match:expr,
                    $(select:
                        {
                            $($select:expr),*
                        }
                    ),*
                        $(,)?
                        $(
                            ,conditions: {
                                $(
                                    and => {
                                        $(
                                            $condition_key:expr => $condition_value:expr
                                        ),*
                                    }
                                )?
                                $(,)?
                                $(
                                    or => {
                                        $(
                                            $condition_or_key:expr => $condition_or_value:expr
                                            ),*
                                    }
                                )?
                            }
                        )?
                        $(,)?
                        $(
                            ,order:
                                {
                                    $(
                                        $order_key:expr => $order_value:expr
                                    )*
                                }
                        )?
                        $(,)?
                        $(
                            ,limit:$limit:expr
                        )?
                    }
                // ),*
        })?
        $(,)?
        $(,order:{
            $(
                $order:expr => $orderby:expr
            ),*
        })?
        $(,)?
        $(,limit:$main_limit:expr)?
        $(,)?
        $(,skip:$main_skip:expr)?
    ) => { ... };
    (connection => $connection:expr,model:$model:expr,select:{$($select_value:expr),*},
    within:{
        lattitude:$lattitude:expr,
        longitude:$longitude:expr
        $(,within:$within:expr)?
    },
    based_on:{
         $location:expr
    }$(,limit:$limit:expr)?) => { ... };
}
Expand description

§Returns

Result<Vec<Vec<std::collections::BTreeMap<String, String>>>, io::Error>

§Example

§Basic

 let find = find_many! {
    connection => postgres,
    model:"billionaires",
    select:{               // optional
        "place"
    },
    case:{              //optional
    (
        "place" => ">22",
        "place" => "<22",
        "place" => "=22"
        ) => (ok:"billion_dollar",
        ok:"billionaire",
        ok:"billionaire"
        ,else:"trillionaire"
    ) => "status"
    },
    conditions:{           // optional
        and => {
            "place" => "san"
        },
        or => {
            "place" => "san"
        }
    },      
    between => {                //optional
        and => {
            "place" => {
                "20" => "22"
            }
        },
        or => {
            "place" => {
                "20" => "22"
            }
        }
    },
    like => {               //optional
        and => {
            "name" => "billionaire"
        },
        or => {
            "billionaire" => "billionaire"
        }
    },
    inside:{                //optional
        "place" => {
            match:  user_id",
            select:{
                "name"
            },
            conditions:{
                and => {
                    "name" => "billionaire"
                }
            },
            order:6,
            limit:6
        }
    },               
    order:{                // optional
        "place" => "asc"
    },
    limit:24,              // optional
    skip:24                // optional
 };
 println!("{:?}", find);
let find = find_many! {
    connection => postgres,
    model:"billionaires",
    select:{            // optional
        "place"
    },
    within:{
        lattitude:"12.971599",
        longitude:"77.594566",
        within:6                // optional
    },
    also_include:{
        "location"
    },
    limit:6             // optional
};