1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
pub use lazy_static::lazy_static;
pub use paste::paste;
pub use pgw::{tokio_postgres, Error, IntoStatement, Pg, Row, Sql, ToSql, ToStatement};

#[macro_export]
macro_rules! q {
  ($db:ident, $name:ident) => {
    $crate::lazy_static! {
      pub static ref $db: $crate::Pg = $crate::Pg::new_with_env(format!("{}_URI",stringify!($db)));
    }
    $crate::paste! {
      q!($db, $name, query, Vec<$crate::Row>);
      q!($db, [<$name 1>], query_one, $crate::Row);
      q!($db, [<$name 01>], query_opt, Option<$crate::Row>);
      q!($db, [<$name E>], execute, u64);
    }
  };
  ($db:ident,$name:ident,$func:ident,$rt:ty) => {
    #[allow(non_snake_case)]
    pub async fn $name<T: $crate::ToStatement>(
      statement: impl $crate::IntoStatement<T>,
      params: &[&(dyn $crate::ToSql + Sync)],
    ) -> Result<$rt, $crate::Error> {
      (*$db).$func(statement, params).await
    }
  };
}