refactor(storage_models): changed CustomResult in storage_models to StorageResult (#158)

This commit is contained in:
Abhishek
2022-12-19 13:41:56 +05:30
committed by GitHub
parent 44feaca4df
commit 8d6d41f2eb
18 changed files with 104 additions and 185 deletions

View File

@ -22,9 +22,7 @@ pub struct TypedSql {
}
impl TypedSql {
pub fn to_field_value_pairs(
&self,
) -> crate::CustomResult<Vec<(&str, String)>, errors::DatabaseError> {
pub fn to_field_value_pairs(&self) -> crate::StorageResult<Vec<(&str, String)>> {
Ok(vec![(
"typed_sql",
serde_json::to_string(self)

View File

@ -24,7 +24,7 @@ pub mod temp_card;
use diesel_impl::{DieselArray, OptionalDieselArray};
pub type CustomResult<T, E> = error_stack::Result<T, E>;
pub type StorageResult<T> = error_stack::Result<T, errors::DatabaseError>;
pub type PgPooledConn = async_bb8_diesel::Connection<diesel::PgConnection>;
/// The types and implementations provided by this module are required for the schema generated by

View File

@ -6,12 +6,12 @@ use crate::{
address::{Address, AddressNew, AddressUpdate, AddressUpdateInternal},
errors,
schema::address::dsl,
CustomResult, PgPooledConn,
PgPooledConn, StorageResult,
};
impl AddressNew {
#[instrument(skip(conn))]
pub async fn insert(self, conn: &PgPooledConn) -> CustomResult<Address, errors::DatabaseError> {
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<Address> {
generics::generic_insert(conn, self).await
}
}
@ -22,7 +22,7 @@ impl Address {
conn: &PgPooledConn,
address_id: String,
address: AddressUpdate,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
match generics::generic_update_by_id::<<Self as HasTable>::Table, _, _, _>(
conn,
address_id.clone(),
@ -51,7 +51,7 @@ impl Address {
pub async fn delete_by_address_id(
conn: &PgPooledConn,
address_id: &str,
) -> CustomResult<bool, errors::DatabaseError> {
) -> StorageResult<bool> {
generics::generic_delete::<<Self as HasTable>::Table, _>(
conn,
dsl::address_id.eq(address_id.to_owned()),
@ -64,7 +64,7 @@ impl Address {
customer_id: &str,
merchant_id: &str,
address: AddressUpdate,
) -> CustomResult<Vec<Self>, errors::DatabaseError> {
) -> StorageResult<Vec<Self>> {
generics::generic_update_with_results::<<Self as HasTable>::Table, _, _, _>(
conn,
dsl::merchant_id
@ -79,7 +79,7 @@ impl Address {
pub async fn find_by_address_id<'a>(
conn: &PgPooledConn,
address_id: &str,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
generics::generic_find_by_id::<<Self as HasTable>::Table, _, _>(conn, address_id.to_owned())
.await
}
@ -88,7 +88,7 @@ impl Address {
pub async fn find_optional_by_address_id<'a>(
conn: &PgPooledConn,
address_id: &str,
) -> CustomResult<Option<Self>, errors::DatabaseError> {
) -> StorageResult<Option<Self>> {
generics::generic_find_by_id_optional::<<Self as HasTable>::Table, _, _>(
conn,
address_id.to_owned(),

View File

@ -4,22 +4,19 @@ use router_env::tracing::{self, instrument};
use super::generics;
use crate::{
configs::{Config, ConfigNew, ConfigUpdate, ConfigUpdateInternal},
errors, CustomResult, PgPooledConn,
errors, PgPooledConn, StorageResult,
};
impl ConfigNew {
#[instrument(skip(conn))]
pub async fn insert(self, conn: &PgPooledConn) -> CustomResult<Config, errors::DatabaseError> {
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<Config> {
generics::generic_insert(conn, self).await
}
}
impl Config {
#[instrument(skip(conn))]
pub async fn find_by_key(
conn: &PgPooledConn,
key: &str,
) -> CustomResult<Self, errors::DatabaseError> {
pub async fn find_by_key(conn: &PgPooledConn, key: &str) -> StorageResult<Self> {
generics::generic_find_by_id::<<Self as HasTable>::Table, _, _>(conn, key.to_owned()).await
}
@ -28,7 +25,7 @@ impl Config {
conn: &PgPooledConn,
key: &str,
config_update: ConfigUpdate,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
match generics::generic_update_by_id::<<Self as HasTable>::Table, _, _, _>(
conn,
key.to_owned(),

View File

@ -9,15 +9,12 @@ use crate::{
},
errors,
schema::connector_response::dsl,
CustomResult, PgPooledConn,
PgPooledConn, StorageResult,
};
impl ConnectorResponseNew {
#[instrument(skip(conn))]
pub async fn insert(
self,
conn: &PgPooledConn,
) -> CustomResult<ConnectorResponse, errors::DatabaseError> {
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<ConnectorResponse> {
generics::generic_insert(conn, self).await
}
}
@ -28,7 +25,7 @@ impl ConnectorResponse {
self,
conn: &PgPooledConn,
connector_response: ConnectorResponseUpdate,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
match generics::generic_update_by_id::<<Self as HasTable>::Table, _, _, _>(
conn,
self.id,
@ -50,7 +47,7 @@ impl ConnectorResponse {
payment_id: &str,
merchant_id: &str,
transaction_id: &str,
) -> CustomResult<ConnectorResponse, errors::DatabaseError> {
) -> StorageResult<ConnectorResponse> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::merchant_id.eq(merchant_id.to_owned()).and(

View File

@ -6,15 +6,12 @@ use crate::{
customers::{Customer, CustomerNew, CustomerUpdate, CustomerUpdateInternal},
errors,
schema::customers::dsl,
CustomResult, PgPooledConn,
PgPooledConn, StorageResult,
};
impl CustomerNew {
#[instrument(skip(conn))]
pub async fn insert(
self,
conn: &PgPooledConn,
) -> CustomResult<Customer, errors::DatabaseError> {
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<Customer> {
generics::generic_insert(conn, self).await
}
}
@ -26,7 +23,7 @@ impl Customer {
customer_id: String,
merchant_id: String,
customer: CustomerUpdate,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
match generics::generic_update_by_id::<<Self as HasTable>::Table, _, _, _>(
conn,
(customer_id.clone(), merchant_id.clone()),
@ -53,7 +50,7 @@ impl Customer {
conn: &PgPooledConn,
customer_id: &str,
merchant_id: &str,
) -> CustomResult<bool, errors::DatabaseError> {
) -> StorageResult<bool> {
generics::generic_delete::<<Self as HasTable>::Table, _>(
conn,
dsl::customer_id
@ -68,7 +65,7 @@ impl Customer {
conn: &PgPooledConn,
customer_id: &str,
merchant_id: &str,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
generics::generic_find_by_id::<<Self as HasTable>::Table, _, _>(
conn,
(customer_id.to_owned(), merchant_id.to_owned()),
@ -81,7 +78,7 @@ impl Customer {
conn: &PgPooledConn,
customer_id: &str,
merchant_id: &str,
) -> CustomResult<Option<Self>, errors::DatabaseError> {
) -> StorageResult<Option<Self>> {
generics::generic_find_by_id_optional::<<Self as HasTable>::Table, _, _>(
conn,
(customer_id.to_owned(), merchant_id.to_owned()),

View File

@ -2,14 +2,13 @@ use router_env::tracing::{self, instrument};
use super::generics;
use crate::{
errors,
events::{Event, EventNew},
CustomResult, PgPooledConn,
PgPooledConn, StorageResult,
};
impl EventNew {
#[instrument(skip(conn))]
pub async fn insert(self, conn: &PgPooledConn) -> CustomResult<Event, errors::DatabaseError> {
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<Event> {
generics::generic_insert(conn, self).await
}
}

View File

@ -21,13 +21,10 @@ use diesel::{
use error_stack::{report, IntoReport, ResultExt};
use router_env::{logger, tracing, tracing::instrument};
use crate::{errors, CustomResult, PgPooledConn};
use crate::{errors, PgPooledConn, StorageResult};
#[instrument(level = "DEBUG", skip_all)]
pub(super) async fn generic_insert<T, V, R>(
conn: &PgPooledConn,
values: V,
) -> CustomResult<R, errors::DatabaseError>
pub(super) async fn generic_insert<T, V, R>(conn: &PgPooledConn, values: V) -> StorageResult<R>
where
T: HasTable<Table = T> + Table + 'static,
V: Debug + Insertable<T>,
@ -60,7 +57,7 @@ pub(super) async fn generic_update<T, V, P>(
conn: &PgPooledConn,
predicate: P,
values: V,
) -> CustomResult<usize, errors::DatabaseError>
) -> StorageResult<usize>
where
T: FilterDsl<P> + HasTable<Table = T> + Table + 'static,
V: AsChangeset<Target = <<T as FilterDsl<P>>::Output as HasTable>::Table> + Debug,
@ -89,7 +86,7 @@ pub(super) async fn generic_update_with_results<T, V, P, R>(
conn: &PgPooledConn,
predicate: P,
values: V,
) -> CustomResult<Vec<R>, errors::DatabaseError>
) -> StorageResult<Vec<R>>
where
T: FilterDsl<P> + HasTable<Table = T> + Table + 'static,
V: AsChangeset<Target = <<T as FilterDsl<P>>::Output as HasTable>::Table> + Debug + 'static,
@ -119,7 +116,7 @@ pub(super) async fn generic_update_by_id<T, V, Pk, R>(
conn: &PgPooledConn,
id: Pk,
values: V,
) -> CustomResult<R, errors::DatabaseError>
) -> StorageResult<R>
where
T: FindDsl<Pk> + HasTable<Table = T> + LimitDsl + Table + 'static,
V: AsChangeset<Target = <<T as FindDsl<Pk>>::Output as HasTable>::Table> + Debug,
@ -163,10 +160,7 @@ where
}
#[instrument(level = "DEBUG", skip_all)]
pub(super) async fn generic_delete<T, P>(
conn: &PgPooledConn,
predicate: P,
) -> CustomResult<bool, errors::DatabaseError>
pub(super) async fn generic_delete<T, P>(conn: &PgPooledConn, predicate: P) -> StorageResult<bool>
where
T: FilterDsl<P> + HasTable<Table = T> + Table + 'static,
<T as FilterDsl<P>>::Output: IntoUpdateTarget,
@ -200,7 +194,7 @@ where
pub(super) async fn generic_delete_one_with_result<T, P, R>(
conn: &PgPooledConn,
predicate: P,
) -> CustomResult<R, errors::DatabaseError>
) -> StorageResult<R>
where
T: FilterDsl<P> + HasTable<Table = T> + Table + 'static,
<T as FilterDsl<P>>::Output: IntoUpdateTarget,
@ -228,10 +222,7 @@ where
}
#[instrument(level = "DEBUG", skip_all)]
async fn generic_find_by_id_core<T, Pk, R>(
conn: &PgPooledConn,
id: Pk,
) -> CustomResult<R, errors::DatabaseError>
async fn generic_find_by_id_core<T, Pk, R>(conn: &PgPooledConn, id: Pk) -> StorageResult<R>
where
T: FindDsl<Pk> + HasTable<Table = T> + LimitDsl + Table + 'static,
<T as FindDsl<Pk>>::Output: QueryFragment<Pg> + RunQueryDsl<PgConnection> + Send + 'static,
@ -256,10 +247,7 @@ where
}
#[instrument(level = "DEBUG", skip_all)]
pub(super) async fn generic_find_by_id<T, Pk, R>(
conn: &PgPooledConn,
id: Pk,
) -> CustomResult<R, errors::DatabaseError>
pub(super) async fn generic_find_by_id<T, Pk, R>(conn: &PgPooledConn, id: Pk) -> StorageResult<R>
where
T: FindDsl<Pk> + HasTable<Table = T> + LimitDsl + Table + 'static,
<T as FindDsl<Pk>>::Output: QueryFragment<Pg> + RunQueryDsl<PgConnection> + Send + 'static,
@ -275,7 +263,7 @@ where
pub(super) async fn generic_find_by_id_optional<T, Pk, R>(
conn: &PgPooledConn,
id: Pk,
) -> CustomResult<Option<R>, errors::DatabaseError>
) -> StorageResult<Option<R>>
where
T: FindDsl<Pk> + HasTable<Table = T> + LimitDsl + Table + 'static,
<T as HasTable>::Table: FindDsl<Pk>,
@ -290,10 +278,7 @@ where
}
#[instrument(level = "DEBUG", skip_all)]
async fn generic_find_one_core<T, P, R>(
conn: &PgPooledConn,
predicate: P,
) -> CustomResult<R, errors::DatabaseError>
async fn generic_find_one_core<T, P, R>(conn: &PgPooledConn, predicate: P) -> StorageResult<R>
where
T: FilterDsl<P> + HasTable<Table = T> + Table + 'static,
<T as FilterDsl<P>>::Output:
@ -317,10 +302,7 @@ where
}
#[instrument(level = "DEBUG", skip_all)]
pub(super) async fn generic_find_one<T, P, R>(
conn: &PgPooledConn,
predicate: P,
) -> CustomResult<R, errors::DatabaseError>
pub(super) async fn generic_find_one<T, P, R>(conn: &PgPooledConn, predicate: P) -> StorageResult<R>
where
T: FilterDsl<P> + HasTable<Table = T> + Table + 'static,
<T as FilterDsl<P>>::Output:
@ -334,7 +316,7 @@ where
pub(super) async fn generic_find_one_optional<T, P, R>(
conn: &PgPooledConn,
predicate: P,
) -> CustomResult<Option<R>, errors::DatabaseError>
) -> StorageResult<Option<R>>
where
T: FilterDsl<P> + HasTable<Table = T> + Table + 'static,
<T as FilterDsl<P>>::Output:
@ -349,7 +331,7 @@ pub(super) async fn generic_filter<T, P, R>(
conn: &PgPooledConn,
predicate: P,
limit: Option<i64>,
) -> CustomResult<Vec<R>, errors::DatabaseError>
) -> StorageResult<Vec<R>>
where
T: FilterDsl<P> + HasTable<Table = T> + Table + 'static,
<T as FilterDsl<P>>::Output: LoadQuery<'static, PgConnection, R> + QueryFragment<Pg>,
@ -377,9 +359,7 @@ where
.attach_printable_lazy(|| "Error filtering records by predicate")
}
fn to_optional<T>(
arg: CustomResult<T, errors::DatabaseError>,
) -> CustomResult<Option<T>, errors::DatabaseError> {
fn to_optional<T>(arg: StorageResult<T>) -> StorageResult<Option<T>> {
match arg {
Ok(value) => Ok(Some(value)),
Err(err) => match err.current_context() {

View File

@ -3,28 +3,21 @@ use router_env::{tracing, tracing::instrument};
use super::generics;
use crate::{
errors,
locker_mock_up::{LockerMockUp, LockerMockUpNew},
schema::locker_mock_up::dsl,
CustomResult, PgPooledConn,
PgPooledConn, StorageResult,
};
impl LockerMockUpNew {
#[instrument(skip(conn))]
pub async fn insert(
self,
conn: &PgPooledConn,
) -> CustomResult<LockerMockUp, errors::DatabaseError> {
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<LockerMockUp> {
generics::generic_insert(conn, self).await
}
}
impl LockerMockUp {
#[instrument(skip(conn))]
pub async fn find_by_card_id(
conn: &PgPooledConn,
card_id: &str,
) -> CustomResult<Self, errors::DatabaseError> {
pub async fn find_by_card_id(conn: &PgPooledConn, card_id: &str) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::card_id.eq(card_id.to_owned()),
@ -33,10 +26,7 @@ impl LockerMockUp {
}
#[instrument(skip(conn))]
pub async fn delete_by_card_id(
conn: &PgPooledConn,
card_id: &str,
) -> CustomResult<Self, errors::DatabaseError> {
pub async fn delete_by_card_id(conn: &PgPooledConn, card_id: &str) -> StorageResult<Self> {
generics::generic_delete_one_with_result::<<Self as HasTable>::Table, _, _>(
conn,
dsl::card_id.eq(card_id.to_owned()),

View File

@ -3,11 +3,11 @@ use error_stack::report;
use router_env::tracing::{self, instrument};
use super::generics;
use crate::{errors, mandate::*, schema::mandate::dsl, CustomResult, PgPooledConn};
use crate::{errors, mandate::*, schema::mandate::dsl, PgPooledConn, StorageResult};
impl MandateNew {
#[instrument(skip(conn))]
pub async fn insert(self, conn: &PgPooledConn) -> CustomResult<Mandate, errors::DatabaseError> {
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<Mandate> {
generics::generic_insert(conn, self).await
}
}
@ -17,7 +17,7 @@ impl Mandate {
conn: &PgPooledConn,
merchant_id: &str,
mandate_id: &str,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::merchant_id
@ -31,7 +31,7 @@ impl Mandate {
conn: &PgPooledConn,
merchant_id: &str,
customer_id: &str,
) -> CustomResult<Vec<Self>, errors::DatabaseError> {
) -> StorageResult<Vec<Self>> {
generics::generic_filter::<<Self as HasTable>::Table, _, _>(
conn,
dsl::merchant_id
@ -47,7 +47,7 @@ impl Mandate {
merchant_id: &str,
mandate_id: &str,
mandate: MandateUpdate,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
generics::generic_update_with_results::<<Self as HasTable>::Table, _, _, _>(
conn,
dsl::merchant_id

View File

@ -8,15 +8,12 @@ use crate::{
MerchantAccount, MerchantAccountNew, MerchantAccountUpdate, MerchantAccountUpdateInternal,
},
schema::merchant_account::dsl,
CustomResult, PgPooledConn,
PgPooledConn, StorageResult,
};
impl MerchantAccountNew {
#[instrument(skip(conn))]
pub async fn insert(
self,
conn: &PgPooledConn,
) -> CustomResult<MerchantAccount, errors::DatabaseError> {
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<MerchantAccount> {
generics::generic_insert(conn, self).await
}
}
@ -27,7 +24,7 @@ impl MerchantAccount {
self,
conn: &PgPooledConn,
merchant_account: MerchantAccountUpdate,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
match generics::generic_update_by_id::<<Self as HasTable>::Table, _, _, _>(
conn,
self.id,
@ -46,7 +43,7 @@ impl MerchantAccount {
pub async fn delete_by_merchant_id(
conn: &PgPooledConn,
merchant_id: &str,
) -> CustomResult<bool, errors::DatabaseError> {
) -> StorageResult<bool> {
generics::generic_delete::<<Self as HasTable>::Table, _>(
conn,
dsl::merchant_id.eq(merchant_id.to_owned()),
@ -58,7 +55,7 @@ impl MerchantAccount {
pub async fn find_by_merchant_id(
conn: &PgPooledConn,
merchant_id: &str,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::merchant_id.eq(merchant_id.to_owned()),
@ -67,10 +64,7 @@ impl MerchantAccount {
}
#[instrument(skip(conn))]
pub async fn find_by_api_key(
conn: &PgPooledConn,
api_key: &str,
) -> CustomResult<Self, errors::DatabaseError> {
pub async fn find_by_api_key(conn: &PgPooledConn, api_key: &str) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::api_key.eq(api_key.to_owned()),
@ -82,7 +76,7 @@ impl MerchantAccount {
pub async fn find_by_publishable_key(
conn: &PgPooledConn,
publishable_key: &str,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::publishable_key.eq(publishable_key.to_owned()),

View File

@ -9,15 +9,12 @@ use crate::{
MerchantConnectorAccountUpdateInternal,
},
schema::merchant_connector_account::dsl,
CustomResult, PgPooledConn,
PgPooledConn, StorageResult,
};
impl MerchantConnectorAccountNew {
#[instrument(skip(conn))]
pub async fn insert(
self,
conn: &PgPooledConn,
) -> CustomResult<MerchantConnectorAccount, errors::DatabaseError> {
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<MerchantConnectorAccount> {
generics::generic_insert(conn, self).await
}
}
@ -28,7 +25,7 @@ impl MerchantConnectorAccount {
self,
conn: &PgPooledConn,
merchant_connector_account: MerchantConnectorAccountUpdate,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
match generics::generic_update_by_id::<<Self as HasTable>::Table, _, _, _>(
conn,
self.id,
@ -48,7 +45,7 @@ impl MerchantConnectorAccount {
conn: &PgPooledConn,
merchant_id: &str,
merchant_connector_id: &i32,
) -> CustomResult<bool, errors::DatabaseError> {
) -> StorageResult<bool> {
generics::generic_delete::<<Self as HasTable>::Table, _>(
conn,
dsl::merchant_id
@ -63,7 +60,7 @@ impl MerchantConnectorAccount {
conn: &PgPooledConn,
merchant_id: &str,
connector: &str,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::merchant_id
@ -78,7 +75,7 @@ impl MerchantConnectorAccount {
conn: &PgPooledConn,
merchant_id: &str,
merchant_connector_id: &i32,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::merchant_id
@ -92,7 +89,7 @@ impl MerchantConnectorAccount {
pub async fn find_by_merchant_id(
conn: &PgPooledConn,
merchant_id: &str,
) -> CustomResult<Vec<Self>, errors::DatabaseError> {
) -> StorageResult<Vec<Self>> {
generics::generic_filter::<<Self as HasTable>::Table, _, _>(
conn,
dsl::merchant_id.eq(merchant_id.to_owned()),

View File

@ -9,15 +9,12 @@ use crate::{
PaymentAttempt, PaymentAttemptNew, PaymentAttemptUpdate, PaymentAttemptUpdateInternal,
},
schema::payment_attempt::dsl,
CustomResult, PgPooledConn,
PgPooledConn, StorageResult,
};
impl PaymentAttemptNew {
#[instrument(skip(conn))]
pub async fn insert(
self,
conn: &PgPooledConn,
) -> CustomResult<PaymentAttempt, errors::DatabaseError> {
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<PaymentAttempt> {
generics::generic_insert(conn, self).await
}
}
@ -28,7 +25,7 @@ impl PaymentAttempt {
self,
conn: &PgPooledConn,
payment_attempt: PaymentAttemptUpdate,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
match generics::generic_update_with_results::<<Self as HasTable>::Table, _, _, _>(
conn,
dsl::payment_id
@ -53,7 +50,7 @@ impl PaymentAttempt {
conn: &PgPooledConn,
payment_id: &str,
merchant_id: &str,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::merchant_id
@ -68,7 +65,7 @@ impl PaymentAttempt {
conn: &PgPooledConn,
payment_id: &str,
merchant_id: &str,
) -> CustomResult<Option<Self>, errors::DatabaseError> {
) -> StorageResult<Option<Self>> {
generics::generic_find_one_optional::<<Self as HasTable>::Table, _, _>(
conn,
dsl::merchant_id
@ -84,7 +81,7 @@ impl PaymentAttempt {
transaction_id: &str,
payment_id: &str,
merchant_id: &str,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::connector_transaction_id
@ -99,7 +96,7 @@ impl PaymentAttempt {
conn: &PgPooledConn,
payment_id: &str,
merchant_id: &str,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
// perform ordering on the application level instead of database level
generics::generic_filter::<<Self as HasTable>::Table, _, Self>(
conn,
@ -125,7 +122,7 @@ impl PaymentAttempt {
conn: &PgPooledConn,
merchant_id: &str,
connector_txn_id: &str,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::merchant_id
@ -140,7 +137,7 @@ impl PaymentAttempt {
conn: &PgPooledConn,
merchant_id: &str,
txn_id: &str,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::merchant_id

View File

@ -8,15 +8,12 @@ use crate::{
PaymentIntent, PaymentIntentNew, PaymentIntentUpdate, PaymentIntentUpdateInternal,
},
schema::payment_intent::dsl,
CustomResult, PgPooledConn,
PgPooledConn, StorageResult,
};
impl PaymentIntentNew {
#[instrument(skip(conn))]
pub async fn insert(
self,
conn: &PgPooledConn,
) -> CustomResult<PaymentIntent, errors::DatabaseError> {
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<PaymentIntent> {
generics::generic_insert(conn, self).await
}
}
@ -27,7 +24,7 @@ impl PaymentIntent {
self,
conn: &PgPooledConn,
payment_intent: PaymentIntentUpdate,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
match generics::generic_update_with_results::<<Self as HasTable>::Table, _, _, _>(
conn,
dsl::payment_id
@ -52,7 +49,7 @@ impl PaymentIntent {
conn: &PgPooledConn,
payment_id: &str,
merchant_id: &str,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::merchant_id
@ -67,7 +64,7 @@ impl PaymentIntent {
conn: &PgPooledConn,
payment_id: &str,
merchant_id: &str,
) -> CustomResult<Option<Self>, errors::DatabaseError> {
) -> StorageResult<Option<Self>> {
generics::generic_find_one_optional::<<Self as HasTable>::Table, _, _>(
conn,
dsl::merchant_id

View File

@ -3,18 +3,14 @@ use router_env::tracing::{self, instrument};
use super::generics;
use crate::{
errors,
payment_method::{PaymentMethod, PaymentMethodNew},
schema::payment_methods::dsl,
CustomResult, PgPooledConn,
PgPooledConn, StorageResult,
};
impl PaymentMethodNew {
#[instrument(skip(conn))]
pub async fn insert(
self,
conn: &PgPooledConn,
) -> CustomResult<PaymentMethod, errors::DatabaseError> {
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<PaymentMethod> {
generics::generic_insert(conn, self).await
}
}
@ -24,7 +20,7 @@ impl PaymentMethod {
pub async fn delete_by_payment_method_id(
conn: &PgPooledConn,
payment_method_id: String,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
generics::generic_delete_one_with_result::<<Self as HasTable>::Table, _, Self>(
conn,
dsl::payment_method_id.eq(payment_method_id),
@ -37,7 +33,7 @@ impl PaymentMethod {
conn: &PgPooledConn,
merchant_id: &str,
payment_method_id: &str,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
generics::generic_delete_one_with_result::<<Self as HasTable>::Table, _, Self>(
conn,
dsl::merchant_id
@ -51,7 +47,7 @@ impl PaymentMethod {
pub async fn find_by_payment_method_id(
conn: &PgPooledConn,
payment_method_id: &str,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::payment_method_id.eq(payment_method_id.to_owned()),
@ -63,7 +59,7 @@ impl PaymentMethod {
pub async fn find_by_merchant_id(
conn: &PgPooledConn,
merchant_id: &str,
) -> CustomResult<Vec<Self>, errors::DatabaseError> {
) -> StorageResult<Vec<Self>> {
generics::generic_filter::<<Self as HasTable>::Table, _, _>(
conn,
dsl::merchant_id.eq(merchant_id.to_owned()),
@ -77,7 +73,7 @@ impl PaymentMethod {
conn: &PgPooledConn,
customer_id: &str,
merchant_id: &str,
) -> CustomResult<Vec<Self>, errors::DatabaseError> {
) -> StorageResult<Vec<Self>> {
generics::generic_filter::<<Self as HasTable>::Table, _, _>(
conn,
dsl::customer_id

View File

@ -9,15 +9,12 @@ use crate::{
ProcessTracker, ProcessTrackerNew, ProcessTrackerUpdate, ProcessTrackerUpdateInternal,
},
schema::process_tracker::dsl,
CustomResult, PgPooledConn,
PgPooledConn, StorageResult,
};
impl ProcessTrackerNew {
#[instrument(skip(conn))]
pub async fn insert_process(
self,
conn: &PgPooledConn,
) -> CustomResult<ProcessTracker, errors::DatabaseError> {
pub async fn insert_process(self, conn: &PgPooledConn) -> StorageResult<ProcessTracker> {
generics::generic_insert(conn, self).await
}
}
@ -28,7 +25,7 @@ impl ProcessTracker {
self,
conn: &PgPooledConn,
process: ProcessTrackerUpdate,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
match generics::generic_update_by_id::<<Self as HasTable>::Table, _, _, _>(
conn,
self.id.clone(),
@ -49,7 +46,7 @@ impl ProcessTracker {
conn: &PgPooledConn,
task_ids: Vec<String>,
task_update: ProcessTrackerUpdate,
) -> CustomResult<usize, errors::DatabaseError> {
) -> StorageResult<usize> {
generics::generic_update::<<Self as HasTable>::Table, _, _>(
conn,
dsl::id.eq_any(task_ids),
@ -59,10 +56,7 @@ impl ProcessTracker {
}
#[instrument(skip(conn))]
pub async fn find_process_by_id(
conn: &PgPooledConn,
id: &str,
) -> CustomResult<Option<Self>, errors::DatabaseError> {
pub async fn find_process_by_id(conn: &PgPooledConn, id: &str) -> StorageResult<Option<Self>> {
generics::generic_find_by_id_optional::<<Self as HasTable>::Table, _, _>(
conn,
id.to_owned(),
@ -77,7 +71,7 @@ impl ProcessTracker {
time_upper_limit: PrimitiveDateTime,
status: enums::ProcessTrackerStatus,
limit: Option<i64>,
) -> CustomResult<Vec<Self>, errors::DatabaseError> {
) -> StorageResult<Vec<Self>> {
generics::generic_filter::<<Self as HasTable>::Table, _, _>(
conn,
dsl::schedule_time
@ -95,7 +89,7 @@ impl ProcessTracker {
time_upper_limit: PrimitiveDateTime,
runner: &str,
limit: u64,
) -> CustomResult<Vec<Self>, errors::DatabaseError> {
) -> StorageResult<Vec<Self>> {
let mut x: Vec<Self> = generics::generic_filter::<<Self as HasTable>::Table, _, _>(
conn,
dsl::schedule_time
@ -115,7 +109,7 @@ impl ProcessTracker {
conn: &PgPooledConn,
ids: Vec<String>,
schedule_time: PrimitiveDateTime,
) -> CustomResult<usize, errors::DatabaseError> {
) -> StorageResult<usize> {
generics::generic_update::<<Self as HasTable>::Table, _, _>(
conn,
dsl::status

View File

@ -6,25 +6,21 @@ use crate::{
errors,
refund::{Refund, RefundNew, RefundUpdate, RefundUpdateInternal},
schema::refund::dsl,
CustomResult, PgPooledConn,
PgPooledConn, StorageResult,
};
// FIXME: Find by partition key : Review
impl RefundNew {
#[instrument(skip(conn))]
pub async fn insert(self, conn: &PgPooledConn) -> CustomResult<Refund, errors::DatabaseError> {
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<Refund> {
generics::generic_insert(conn, self).await
}
}
impl Refund {
#[instrument(skip(conn))]
pub async fn update(
self,
conn: &PgPooledConn,
refund: RefundUpdate,
) -> CustomResult<Self, errors::DatabaseError> {
pub async fn update(self, conn: &PgPooledConn, refund: RefundUpdate) -> StorageResult<Self> {
match generics::generic_update_by_id::<<Self as HasTable>::Table, _, _, _>(
conn,
self.id,
@ -46,7 +42,7 @@ impl Refund {
conn: &PgPooledConn,
merchant_id: &str,
refund_id: &str,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::merchant_id
@ -61,7 +57,7 @@ impl Refund {
conn: &PgPooledConn,
internal_reference_id: &str,
merchant_id: &str,
) -> CustomResult<Self, errors::DatabaseError> {
) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::merchant_id
@ -76,7 +72,7 @@ impl Refund {
conn: &PgPooledConn,
merchant_id: &str,
txn_id: &str,
) -> CustomResult<Vec<Self>, errors::DatabaseError> {
) -> StorageResult<Vec<Self>> {
generics::generic_filter::<<Self as HasTable>::Table, _, _>(
conn,
dsl::merchant_id
@ -92,7 +88,7 @@ impl Refund {
conn: &PgPooledConn,
payment_id: &str,
merchant_id: &str,
) -> CustomResult<Vec<Self>, errors::DatabaseError> {
) -> StorageResult<Vec<Self>> {
generics::generic_filter::<<Self as HasTable>::Table, _, _>(
conn,
dsl::merchant_id

View File

@ -3,28 +3,21 @@ use router_env::tracing::{self, instrument};
use super::generics;
use crate::{
errors,
schema::temp_card::dsl,
temp_card::{TempCard, TempCardNew},
CustomResult, PgPooledConn,
PgPooledConn, StorageResult,
};
impl TempCardNew {
#[instrument(skip(conn))]
pub async fn insert(
self,
conn: &PgPooledConn,
) -> CustomResult<TempCard, errors::DatabaseError> {
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<TempCard> {
generics::generic_insert(conn, self).await
}
}
impl TempCard {
#[instrument(skip(conn))]
pub async fn insert_with_token(
self,
conn: &PgPooledConn,
) -> CustomResult<Self, errors::DatabaseError> {
pub async fn insert_with_token(self, conn: &PgPooledConn) -> StorageResult<Self> {
generics::generic_insert(conn, self).await
}
@ -32,7 +25,7 @@ impl TempCard {
pub async fn find_by_transaction_id(
conn: &PgPooledConn,
transaction_id: &str,
) -> CustomResult<Option<TempCard>, errors::DatabaseError> {
) -> StorageResult<Option<TempCard>> {
generics::generic_find_one_optional::<<Self as HasTable>::Table, _, _>(
conn,
dsl::txn_id.eq(transaction_id.to_owned()),
@ -41,10 +34,7 @@ impl TempCard {
}
#[instrument(skip(conn))]
pub async fn find_by_token(
conn: &PgPooledConn,
token: &i32,
) -> CustomResult<Self, errors::DatabaseError> {
pub async fn find_by_token(conn: &PgPooledConn, token: &i32) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::id.eq(token.to_owned()),