mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 00:49:42 +08:00
refactor(events): populate object identifiers in outgoing webhooks analytics events during retries (#5067)
This commit is contained in:
@ -95,3 +95,43 @@ macro_rules! collect_missing_value_keys {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! impl_to_sql_from_sql_json {
|
||||
($type:ty, $diesel_type:ty) => {
|
||||
#[allow(unused_qualifications)]
|
||||
impl diesel::serialize::ToSql<$diesel_type, diesel::pg::Pg> for $type {
|
||||
fn to_sql<'b>(
|
||||
&'b self,
|
||||
out: &mut diesel::serialize::Output<'b, '_, diesel::pg::Pg>,
|
||||
) -> diesel::serialize::Result {
|
||||
let value = serde_json::to_value(self)?;
|
||||
|
||||
// the function `reborrow` only works in case of `Pg` backend. But, in case of other backends
|
||||
// please refer to the diesel migration blog:
|
||||
// https://github.com/Diesel-rs/Diesel/blob/master/guide_drafts/migration_guide.md#changed-tosql-implementations
|
||||
<serde_json::Value as diesel::serialize::ToSql<
|
||||
$diesel_type,
|
||||
diesel::pg::Pg,
|
||||
>>::to_sql(&value, &mut out.reborrow())
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused_qualifications)]
|
||||
impl diesel::deserialize::FromSql<$diesel_type, diesel::pg::Pg> for $type {
|
||||
fn from_sql(
|
||||
bytes: <diesel::pg::Pg as diesel::backend::Backend>::RawValue<'_>,
|
||||
) -> diesel::deserialize::Result<Self> {
|
||||
let value = <serde_json::Value as diesel::deserialize::FromSql<
|
||||
$diesel_type,
|
||||
diesel::pg::Pg,
|
||||
>>::from_sql(bytes)?;
|
||||
Ok(serde_json::from_value(value)?)
|
||||
}
|
||||
}
|
||||
};
|
||||
($type: ty) => {
|
||||
$crate::impl_to_sql_from_sql_json!($type, diesel::sql_types::Json);
|
||||
$crate::impl_to_sql_from_sql_json!($type, diesel::sql_types::Jsonb);
|
||||
};
|
||||
}
|
||||
|
||||
@ -207,29 +207,7 @@ impl FromStr for SemanticVersion {
|
||||
}
|
||||
}
|
||||
|
||||
impl<DB: Backend> FromSql<Jsonb, DB> for SemanticVersion
|
||||
where
|
||||
serde_json::Value: FromSql<Jsonb, DB>,
|
||||
{
|
||||
fn from_sql(bytes: DB::RawValue<'_>) -> deserialize::Result<Self> {
|
||||
let value = <serde_json::Value as FromSql<Jsonb, DB>>::from_sql(bytes)?;
|
||||
Ok(serde_json::from_value(value)?)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToSql<Jsonb, diesel::pg::Pg> for SemanticVersion
|
||||
where
|
||||
serde_json::Value: ToSql<Jsonb, diesel::pg::Pg>,
|
||||
{
|
||||
fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, diesel::pg::Pg>) -> diesel::serialize::Result {
|
||||
let value = serde_json::to_value(self)?;
|
||||
|
||||
// the function `reborrow` only works in case of `Pg` backend. But, in case of other backends
|
||||
// please refer to the diesel migration blog:
|
||||
// https://github.com/Diesel-rs/Diesel/blob/master/guide_drafts/migration_guide.md#changed-tosql-implementations
|
||||
<serde_json::Value as ToSql<Jsonb, diesel::pg::Pg>>::to_sql(&value, &mut out.reborrow())
|
||||
}
|
||||
}
|
||||
crate::impl_to_sql_from_sql_json!(SemanticVersion);
|
||||
|
||||
/// Amount convertor trait for connector
|
||||
pub trait AmountConvertor: Send {
|
||||
@ -692,26 +670,4 @@ pub struct ChargeRefunds {
|
||||
pub revert_transfer: Option<bool>,
|
||||
}
|
||||
|
||||
impl<DB: Backend> FromSql<Jsonb, DB> for ChargeRefunds
|
||||
where
|
||||
serde_json::Value: FromSql<Jsonb, DB>,
|
||||
{
|
||||
fn from_sql(bytes: DB::RawValue<'_>) -> deserialize::Result<Self> {
|
||||
let value = <serde_json::Value as FromSql<Jsonb, DB>>::from_sql(bytes)?;
|
||||
Ok(serde_json::from_value(value)?)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToSql<Jsonb, diesel::pg::Pg> for ChargeRefunds
|
||||
where
|
||||
serde_json::Value: ToSql<Jsonb, diesel::pg::Pg>,
|
||||
{
|
||||
fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, diesel::pg::Pg>) -> diesel::serialize::Result {
|
||||
let value = serde_json::to_value(self)?;
|
||||
|
||||
// the function `reborrow` only works in case of `Pg` backend. But, in case of other backends
|
||||
// please refer to the diesel migration blog:
|
||||
// https://github.com/Diesel-rs/Diesel/blob/master/guide_drafts/migration_guide.md#changed-tosql-implementations
|
||||
<serde_json::Value as ToSql<Jsonb, diesel::pg::Pg>>::to_sql(&value, &mut out.reborrow())
|
||||
}
|
||||
}
|
||||
crate::impl_to_sql_from_sql_json!(ChargeRefunds);
|
||||
|
||||
Reference in New Issue
Block a user