pub extern crate paste;
#[macro_export]
macro_rules! serialize_rows_static {
($db_type:ident, $(($table_name:literal, $struct:ty)),+ $(,)?) => {
fn serialize_rows_static(data: &$crate::queries::serialize::QueryData<$crate::database_row!($db_type)>, table: &str) -> serde_json::Value {
match table {
$(
$table_name => $crate::database::serialize_rows::<$struct, $crate::database_row!($db_type)>(data),
)+
_ => panic!("Table not found"),
}
}
};
}
#[macro_export]
macro_rules! granular_operations {
($db_type:ident, $(($table_name:literal, $struct:ty)),+ $(,)?) => {
async fn granular_operation_static(
operation: $crate::operations::serialize::GranularOperation,
pool: &$crate::database_pool!($db_type),
) -> serde_json::Value {
match operation.get_table() {
$(
$table_name => {
let result: Option<$crate::operations::serialize::OperationNotification<$struct>> =
$crate::granular_operation_fn!($db_type)(operation, pool).await;
serde_json::to_value(result).unwrap()
}
)+
_ => panic!("Table not found"),
}
}
};
}
#[macro_export]
macro_rules! database_pool {
(sqlite) => {
sqlx::Pool<sqlx::Sqlite>
};
(mysql) => {
sqlx::Pool<sqlx::MySql>
};
(postgresql) => {
sqlx::Pool<sqlx::Postgres>
};
}
#[macro_export]
macro_rules! database_row {
(sqlite) => {
sqlx::sqlite::SqliteRow
};
(mysql) => {
sqlx::mysql::MySqlRow
};
(postgresql) => {
sqlx::postgres::PgRow
};
}
#[macro_export]
macro_rules! granular_operation_fn {
(sqlite) => {
$crate::database::sqlite::granular_operation_sqlite
};
(mysql) => {
$crate::database::mysql::granular_operation_mysql
};
(postgresql) => {
$crate::database::postgresql::granular_operation_postgresql
};
}
#[macro_export]
macro_rules! fetch_query_fn {
(sqlite) => {
$crate::database::sqlite::fetch_sqlite_query
};
(mysql) => {
$crate::database::mysql::fetch_mysql_query
};
(postgresql) => {
$crate::database::postgresql::fetch_postgresql_query
};
}