mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 01:27:31 +08:00
feat(drainer): added drainer which reads from redis stream and executes queries on DB (#142)
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
use diesel::{associations::HasTable, BoolExpressionMethods, ExpressionMethods};
|
||||
use router_env::tracing::{self, instrument};
|
||||
|
||||
use super::generics::{self, ExecuteQuery, RawQuery, RawSqlQuery};
|
||||
use super::generics;
|
||||
use crate::{
|
||||
errors,
|
||||
payment_intent::{
|
||||
@ -17,15 +17,7 @@ impl PaymentIntentNew {
|
||||
self,
|
||||
conn: &PgPooledConn,
|
||||
) -> CustomResult<PaymentIntent, errors::DatabaseError> {
|
||||
generics::generic_insert::<_, _, PaymentIntent, _>(conn, self, ExecuteQuery::new()).await
|
||||
}
|
||||
|
||||
#[instrument(skip(conn))]
|
||||
pub async fn insert_query(
|
||||
self,
|
||||
conn: &PgPooledConn,
|
||||
) -> CustomResult<RawSqlQuery, errors::DatabaseError> {
|
||||
generics::generic_insert::<_, _, PaymentIntent, _>(conn, self, RawQuery).await
|
||||
generics::generic_insert(conn, self).await
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,11 +28,12 @@ impl PaymentIntent {
|
||||
conn: &PgPooledConn,
|
||||
payment_intent: PaymentIntentUpdate,
|
||||
) -> CustomResult<Self, errors::DatabaseError> {
|
||||
match generics::generic_update_by_id::<<Self as HasTable>::Table, _, _, Self, _>(
|
||||
match generics::generic_update_with_results::<<Self as HasTable>::Table, _, _, _>(
|
||||
conn,
|
||||
self.id,
|
||||
dsl::payment_id
|
||||
.eq(self.payment_id.to_owned())
|
||||
.and(dsl::merchant_id.eq(self.merchant_id.to_owned())),
|
||||
PaymentIntentUpdateInternal::from(payment_intent),
|
||||
ExecuteQuery::new(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
@ -48,25 +41,12 @@ impl PaymentIntent {
|
||||
errors::DatabaseError::NoFieldsToUpdate => Ok(self),
|
||||
_ => Err(error),
|
||||
},
|
||||
result => result,
|
||||
Ok(mut payment_intents) => payment_intents
|
||||
.pop()
|
||||
.ok_or(error_stack::report!(errors::DatabaseError::NotFound)),
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(conn))]
|
||||
pub async fn update_query(
|
||||
self,
|
||||
conn: &PgPooledConn,
|
||||
payment_intent: PaymentIntentUpdate,
|
||||
) -> CustomResult<RawSqlQuery, errors::DatabaseError> {
|
||||
generics::generic_update_by_id::<<Self as HasTable>::Table, _, _, Self, _>(
|
||||
conn,
|
||||
self.id,
|
||||
PaymentIntentUpdateInternal::from(payment_intent),
|
||||
RawQuery,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[instrument(skip(conn))]
|
||||
pub async fn find_by_payment_id_merchant_id(
|
||||
conn: &PgPooledConn,
|
||||
|
||||
Reference in New Issue
Block a user