Skip to content

Commit fb22cb7

Browse files
committed
chore: address review comments
1 parent 35290fd commit fb22cb7

File tree

5 files changed

+56
-43
lines changed

5 files changed

+56
-43
lines changed

crates/diesel_models/src/customers.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use crate::schema::customers;
99
use crate::{
1010
diesel_impl::RequiredFromNullableWithDefault, enums::DeleteStatus, schema_v2::customers,
1111
};
12-
#[cfg(feature = "v2")]
13-
crate::impl_from_required_from_nullable_with_default!(DeleteStatus);
12+
1413
#[cfg(feature = "v1")]
1514
#[derive(
1615
Clone, Debug, router_derive::DebugAsDisplay, serde::Deserialize, serde::Serialize, Insertable,

crates/diesel_models/src/lib.rs

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ pub mod user_key_store;
6161
pub mod user_role;
6262

6363
use diesel_impl::{DieselArray, OptionalDieselArray};
64-
pub use diesel_impl::{RequiredFromNullable, RequiredFromNullableWithDefault};
64+
#[cfg(feature = "v2")]
65+
use diesel_impl::{RequiredFromNullable, RequiredFromNullableWithDefault};
6566

6667
pub type StorageResult<T> = error_stack::Result<T, errors::DatabaseError>;
6768
pub type PgPooledConn = async_bb8_diesel::Connection<diesel::PgConnection>;
@@ -72,7 +73,6 @@ pub use self::{
7273
payment_intent::*, payment_method::*, payout_attempt::*, payouts::*, process_tracker::*,
7374
refund::*, reverse_lookup::*, user_authentication_method::*,
7475
};
75-
7676
/// The types and implementations provided by this module are required for the schema generated by
7777
/// `diesel_cli` 2.0 to work with the types defined in Rust code. This is because
7878
/// [`diesel`][diesel] 2.0 [changed the nullability of array elements][diesel-2.0-array-nullability],
@@ -131,20 +131,22 @@ pub(crate) mod diesel_impl {
131131
Ok(Self(row))
132132
}
133133
}
134-
134+
#[cfg(feature = "v2")]
135135
/// If the DB value is null, this wrapper will return an error when deserializing.
136136
///
137137
/// This is useful when you want to ensure that a field is always present, even if the database
138138
/// value is NULL. If the database column contains a NULL value, an error will be returned.
139139
pub struct RequiredFromNullable<T>(T);
140140

141+
#[cfg(feature = "v2")]
141142
impl<T> RequiredFromNullable<T> {
142143
/// Extracts the inner value from the wrapper
143144
pub fn into_inner(self) -> T {
144145
self.0
145146
}
146147
}
147148

149+
#[cfg(feature = "v2")]
148150
impl<T, ST, DB> Queryable<Nullable<ST>, DB> for RequiredFromNullable<T>
149151
where
150152
DB: diesel::backend::Backend,
@@ -165,19 +167,20 @@ pub(crate) mod diesel_impl {
165167
}
166168
}
167169

170+
#[cfg(feature = "v2")]
168171
/// If the DB value is null, this wrapper will provide a default value for the type `T`.
169172
///
170173
/// This is useful when you want to ensure that a field is always present, even if the database
171174
/// value is NULL. The default value is provided by the `Default` trait implementation of `T`.
172175
pub struct RequiredFromNullableWithDefault<T>(T);
173-
176+
#[cfg(feature = "v2")]
174177
impl<T> RequiredFromNullableWithDefault<T> {
175178
/// Extracts the inner value from the wrapper
176179
pub fn into_inner(self) -> T {
177180
self.0
178181
}
179182
}
180-
183+
#[cfg(feature = "v2")]
181184
impl<T, ST, DB> Queryable<Nullable<ST>, DB> for RequiredFromNullableWithDefault<T>
182185
where
183186
DB: diesel::backend::Backend,
@@ -198,34 +201,54 @@ pub(crate) mod diesel_impl {
198201
}
199202
}
200203
}
201-
}
202204

203-
/// Macro to implement From trait for types wrapped in RequiredFromNullable
204-
#[macro_export]
205-
macro_rules! impl_from_required_from_nullable {
206-
($($type:ty),* $(,)?) => {
207-
$(
208-
impl From<$crate::RequiredFromNullable<$type>> for $type {
209-
fn from(wrapper: $crate::RequiredFromNullable<$type>) -> Self {
210-
wrapper.into_inner()
205+
#[cfg(feature = "v2")]
206+
/// Macro to implement From trait for types wrapped in RequiredFromNullable
207+
#[macro_export]
208+
macro_rules! impl_from_required_from_nullable {
209+
($($type:ty),* $(,)?) => {
210+
$(
211+
impl From<$crate::RequiredFromNullable<$type>> for $type {
212+
fn from(wrapper: $crate::RequiredFromNullable<$type>) -> Self {
213+
wrapper.into_inner()
214+
}
211215
}
212-
}
213-
)*
214-
};
215-
}
216+
)*
217+
};
218+
}
216219

217-
/// Macro to implement From trait for types wrapped in RequiredFromNullableWithDefault
218-
#[macro_export]
219-
macro_rules! impl_from_required_from_nullable_with_default {
220-
($($type:ty),* $(,)?) => {
221-
$(
222-
impl From<$crate::RequiredFromNullableWithDefault<$type>> for $type {
223-
fn from(wrapper: $crate::RequiredFromNullableWithDefault<$type>) -> Self {
224-
wrapper.into_inner()
220+
#[cfg(feature = "v2")]
221+
/// Macro to implement From trait for types wrapped in RequiredFromNullableWithDefault
222+
#[macro_export]
223+
macro_rules! impl_from_required_from_nullable_with_default {
224+
($($type:ty),* $(,)?) => {
225+
$(
226+
impl From<$crate::RequiredFromNullableWithDefault<$type>> for $type {
227+
fn from(wrapper: $crate::RequiredFromNullableWithDefault<$type>) -> Self {
228+
wrapper.into_inner()
229+
}
225230
}
226-
}
227-
)*
228-
};
231+
)*
232+
};
233+
}
234+
#[cfg(feature = "v2")]
235+
use common_utils::{id_type, types};
236+
237+
#[cfg(feature = "v2")]
238+
use crate::enums;
239+
#[cfg(feature = "v2")]
240+
crate::impl_from_required_from_nullable_with_default!(enums::DeleteStatus);
241+
242+
#[cfg(feature = "v2")]
243+
crate::impl_from_required_from_nullable!(
244+
enums::AuthenticationType,
245+
types::MinorUnit,
246+
enums::PaymentMethod,
247+
enums::Currency,
248+
id_type::ProfileId,
249+
time::PrimitiveDateTime,
250+
id_type::RefundReferenceId,
251+
);
229252
}
230253

231254
pub(crate) mod metrics {

crates/diesel_models/src/payment_attempt.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ use crate::enums as storage_enums;
1616
use crate::schema::payment_attempt;
1717
#[cfg(feature = "v2")]
1818
use crate::schema_v2::payment_attempt;
19-
crate::impl_from_required_from_nullable!(
20-
storage_enums::AuthenticationType,
21-
MinorUnit,
22-
storage_enums::PaymentMethod
23-
);
19+
2420
common_utils::impl_to_sql_from_sql_json!(ConnectorMandateReferenceId);
2521
#[derive(
2622
Clone, Debug, serde::Deserialize, serde::Serialize, Eq, PartialEq, diesel::AsExpression,

crates/diesel_models/src/payment_intent.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ use crate::types::{FeatureMetadata, OrderDetailsWithAmount};
1414
#[cfg(feature = "v2")]
1515
use crate::RequiredFromNullable;
1616
use crate::{business_profile::PaymentLinkBackgroundImageConfig, enums as storage_enums};
17-
crate::impl_from_required_from_nullable!(
18-
storage_enums::Currency,
19-
common_utils::id_type::ProfileId,
20-
PrimitiveDateTime
21-
);
17+
2218
#[cfg(feature = "v2")]
2319
#[derive(Clone, Debug, PartialEq, Identifiable, Queryable, Serialize, Deserialize, Selectable)]
2420
#[diesel(table_name = payment_intent, primary_key(id), check_for_backend(diesel::pg::Pg))]

crates/diesel_models/src/refund.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ use crate::schema::refund;
1313
use crate::schema_v2::refund;
1414
#[cfg(feature = "v2")]
1515
use crate::RequiredFromNullable;
16-
#[cfg(feature = "v2")]
17-
crate::impl_from_required_from_nullable!(id_type::RefundReferenceId);
16+
1817
#[cfg(feature = "v1")]
1918
#[derive(
2019
Clone,

0 commit comments

Comments
 (0)