#[macro_export]
macro_rules! impl_bind_sqlx_param_value {
(
$query:ident, $p_val:ident, [$($vtype:ty),+]
) => {
paste::paste!{
match $p_val {
$(
dysql_tpl::SimpleValue::[<t_ $vtype>](val) => $query.bind(val),
)*
dysql_tpl::SimpleValue::t_str(val) => $query.bind(unsafe {&*val.0}),
dysql_tpl::SimpleValue::t_String(val) => $query.bind(unsafe {&*val.0}),
dysql_tpl::SimpleValue::None(val) => $query.bind(val),
_ => Err(crate::DySqlError(crate::ErrorInner::new(crate::Kind::BindParamterError, None, Some(format!("the type of {:?} is not support", $p_val)))))?,
}
}
};
}
pub trait SqlxExecutorAdatper
{
type DB: sqlx::Database;
type Row: sqlx::Row<Database = Self::DB>;
fn get_dialect(&self) -> crate::SqlDialect
{
#[cfg(feature = "sqlx-postgres")]
if std::any::TypeId::of::<Self::DB>() == std::any::TypeId::of::<sqlx::Postgres>() {
return crate::SqlDialect::postgres
}
#[cfg(feature = "sqlx-mysql")]
if std::any::TypeId::of::<Self::DB>() == std::any::TypeId::of::<sqlx::MySql>() {
return crate::SqlDialect::mysql
}
#[cfg(feature = "sqlx-sqlite")]
if std::any::TypeId::of::<Self::DB>() == std::any::TypeId::of::<sqlx::Sqlite>() {
return crate::SqlDialect::sqlite
}
panic!("only support 'postgres', 'mysql', 'sqlite' sql dialect")
}
async fn dy_fetch_all<D, U>(self, template_id: u64, named_template: std::sync::Arc<dysql_tpl::Template>, dto: Option<D>)
-> Result<Vec<U>, crate::DySqlError>
where
D: dysql_tpl::Content + Send + Sync,
for<'r> U: sqlx::FromRow<'r, Self::Row> + Send + Unpin;
async fn dy_fetch_one<D, U>(self, template_id: u64, named_template: std::sync::Arc<dysql_tpl::Template>, dto: Option<D>)
-> Result<U, crate::DySqlError>
where
D: dysql_tpl::Content + Send + Sync,
for<'r> U: sqlx::FromRow<'r, Self::Row> + Send + Unpin;
async fn dy_fetch_scalar<D, U>(self, template_id: u64, named_template: std::sync::Arc<dysql_tpl::Template>, dto: Option<D>)
-> Result<U, crate::DySqlError>
where
D: dysql_tpl::Content + Send + Sync,
for<'r> U: sqlx::Decode<'r, Self::DB> + sqlx::Type<Self::DB> + Send + Unpin;
async fn dy_execute<D>(self, template_id: u64, named_template: std::sync::Arc<dysql_tpl::Template>, dto: Option<D>)
-> Result<u64, crate::DySqlError>
where
D: dysql_tpl::Content + Send + Sync;
async fn dy_insert<D, U>(self, template_id: u64, named_template: std::sync::Arc<dysql_tpl::Template>, dto: Option<D>)
-> Result<Option<U>, crate::DySqlError>
where
D: dysql_tpl::Content + Send + Sync,
for<'r> U: sqlx::Decode<'r, Self::DB> + sqlx::Type<Self::DB> + Send + Unpin;
async fn dy_fetch_insert_id<U>(self)
-> Result<Option<U>, crate::DySqlError>
where
for<'r> U: sqlx::Decode<'r, Self::DB> + sqlx::Type<Self::DB> + Send + Unpin;
async fn dy_page_count<D, U>(self, template_id: u64, named_template: std::sync::Arc<dysql_tpl::Template>, dto: Option<D>)
-> Result<U, crate::DySqlError>
where
D: dysql_tpl::Content + Send + Sync,
for<'r> U: sqlx::Decode<'r, Self::DB> + sqlx::Type<Self::DB> + Send + Unpin;
async fn dy_page_all<D, U>(self, template_id: u64, named_template: std::sync::Arc<dysql_tpl::Template>, page_dto: &crate::PageDto<D>)
-> Result<crate::Pagination<U>, crate::DySqlError>
where
D: dysql_tpl::Content + Send + Sync,
for<'r> U: sqlx::FromRow<'r, Self::Row> + Send + Unpin;
}