mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 05:17:02 +08:00
feat(drainer): added drainer which reads from redis stream and executes queries on DB (#142)
This commit is contained in:
61
crates/storage_models/src/kv.rs
Normal file
61
crates/storage_models/src/kv.rs
Normal file
@ -0,0 +1,61 @@
|
||||
use error_stack::{IntoReport, ResultExt};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
errors,
|
||||
payment_attempt::{PaymentAttempt, PaymentAttemptNew, PaymentAttemptUpdate},
|
||||
payment_intent::{PaymentIntent, PaymentIntentNew, PaymentIntentUpdate},
|
||||
};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case", tag = "db_op", content = "data")]
|
||||
pub enum DBOperation {
|
||||
Insert { insertable: Insertable },
|
||||
Update { updatable: Updateable },
|
||||
Delete,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct TypedSql {
|
||||
#[serde(flatten)]
|
||||
pub op: DBOperation,
|
||||
}
|
||||
|
||||
impl TypedSql {
|
||||
pub fn to_field_value_pairs(
|
||||
&self,
|
||||
) -> crate::CustomResult<Vec<(&str, String)>, errors::DatabaseError> {
|
||||
Ok(vec![(
|
||||
"typed_sql",
|
||||
serde_json::to_string(self)
|
||||
.into_report()
|
||||
.change_context(errors::DatabaseError::QueryGenerationFailed)?,
|
||||
)])
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case", tag = "table", content = "data")]
|
||||
pub enum Insertable {
|
||||
PaymentIntent(PaymentIntentNew),
|
||||
PaymentAttempt(PaymentAttemptNew),
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case", tag = "table", content = "data")]
|
||||
pub enum Updateable {
|
||||
PaymentIntentUpdate(PaymentIntentUpdateMems),
|
||||
PaymentAttemptUpdate(PaymentAttemptUpdateMems),
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct PaymentIntentUpdateMems {
|
||||
pub orig: PaymentIntent,
|
||||
pub update_data: PaymentIntentUpdate,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct PaymentAttemptUpdateMems {
|
||||
pub orig: PaymentAttempt,
|
||||
pub update_data: PaymentAttemptUpdate,
|
||||
}
|
||||
Reference in New Issue
Block a user