db_helpers/
pg.rs

1#[cfg(feature = "pg")]
2#[macro_export]
3macro_rules! pg_fns {
4	(from_table $name:ident $($rust_name:ident,$db_name:tt);+) => {
5		impl From<&$crate::Row> for $name{
6			fn from(r:&$crate::Row)->Self{
7				Self{
8					$($rust_name:r.get(stringify!($db_name))),+
9				}
10			}
11		}
12		impl From<$crate::Row> for $name{
13			fn from(r:$crate::Row)->Self{
14				Self::from(&r)
15			}
16		}
17  };
18	(create_table_str $name:ident $($db_name:tt,$db_type:expr);+) => {
19			pub fn to_pg_create_table_str()->String{
20				let fields = [
21					$(concat!("\"",stringify!($db_name),"\""," ",$db_type)),+
22				];
23				format!("CREATE TABLE IF NOT EXISTS {} ({});",<Self as $crate::legacy::Table>::table_name(),fields.join(","))
24			}
25  };
26}
27/// add here the default macros for no backend enabled
28#[cfg(not(feature = "pg"))]
29#[macro_export]
30macro_rules! pg_fns {
31	(from_table $name:ident $($rust_name:ident,$db_name:tt);+) => {};
32	(create_table_str $name:ident $($db_name:tt,$db_type:expr);+) => {};
33}
34#[cfg(feature = "pg")]
35#[macro_export]
36macro_rules! pg_params {
37	($($param:expr),*) => {
38		&[$(&$param),*]
39	};
40}