ydb/
sugar.rs

1/// sugar for manual construct query params
2///
3/// similar to Query::new("SELECT 1").with_params(HashMap::<String, Value>::from_iter(
4///     [
5///         ("$val1".to_string(), 123.into()),
6///         ("$val2".to_string(), "asdas".to_string().into()),
7///     ]
8/// )
9///
10/// Example:
11/// ```no_run
12/// use ydb::{Query, ydb_params};
13///
14/// Query::new("SELECT 1").with_params( ydb_params!( "$val1" => 123, "$val2" => "asdas" ));
15/// ```
16#[macro_export]
17macro_rules! ydb_params {
18    (
19        $($name:expr => $val:expr ),+ $(,)?
20    ) => {
21        std::collections::HashMap::<String, $crate::Value>::from_iter([
22            $( ($name.into(), $val.into()), )+
23        ])
24    };
25}
26
27///  Sugar for manual construct structs
28///  Example:
29/// ```
30///  use ydb::{Value, ydb_struct};
31///  let s_manual = Value::struct_from_fields(vec![
32///     ("field1".to_string(), 1.into()),
33///     ("field2".to_string(), "test".into()),
34///  ]);
35///
36///  let s_macros = ydb_struct!(
37///     "field1" => 1,
38///     "field2" => "test"
39///  );
40///  assert!(s_manual == s_macros)
41/// ```
42#[macro_export]
43macro_rules! ydb_struct {
44    (
45        $($field_name:expr => $val:expr),+ $(,)?
46    ) => {
47        $crate::Value::struct_from_fields(vec![
48            $( ($field_name.into(), $val.into()), )+
49        ])
50    }
51}