Skip to content

Commit 44f22d3

Browse files
committed
Added postgres-only types
1 parent 1548216 commit 44f22d3

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ sqlite = [
7171
## Exclusive drivers
7272
postgres-only = [
7373
"postgres",
74+
"rorm-sql/postgres-only",
75+
"sqlx/mac_address",
76+
"sqlx/ipnetwork",
77+
"sqlx/bit-vec",
7478
]
7579

7680
# sqlx runtime

src/sqlx_impl/utils.rs

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
//! Utility functions
22
33
use rorm_sql::value::{NullType, Value};
4-
use sqlx::types::chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, Utc};
5-
use sqlx::types::time::{Date, OffsetDateTime, PrimitiveDateTime, Time};
6-
use sqlx::types::{Json, Uuid};
4+
use sqlx::types::Json;
75

8-
use super::any::AnyQuery;
6+
use super::any::{AnyEncode, AnyQuery, AnyType};
97

108
/// This helper method is used to bind ConditionValues to the query.
119
pub fn bind_param<'post_query, 'query>(query: &mut AnyQuery<'query>, param: Value<'post_query>)
@@ -41,6 +39,13 @@ where
4139

4240
Value::JsonValue(x) => query.bind(Json(x)),
4341

42+
#[cfg(feature = "postgres-only")]
43+
Value::MacAddress(x) => query.bind(x),
44+
#[cfg(feature = "postgres-only")]
45+
Value::IpNetwork(x) => query.bind(x),
46+
#[cfg(feature = "postgres-only")]
47+
Value::BitVec(x) => query.bind(x),
48+
4449
Value::Null(null_type) => match null_type {
4550
NullType::String => query.bind(None::<&str>),
4651
NullType::I64 => query.bind(None::<i64>),
@@ -52,21 +57,37 @@ where
5257
NullType::Binary => query.bind(None::<&[u8]>),
5358
NullType::Choice => {}
5459

55-
NullType::ChronoNaiveTime => query.bind(None::<NaiveTime>),
56-
NullType::ChronoNaiveDate => query.bind(None::<NaiveDate>),
57-
NullType::ChronoNaiveDateTime => query.bind(None::<NaiveDateTime>),
58-
NullType::ChronoDateTime => query.bind(None::<DateTime<Utc>>),
60+
NullType::ChronoNaiveTime => query.bind(none(Value::ChronoNaiveTime)),
61+
NullType::ChronoNaiveDate => query.bind(none(Value::ChronoNaiveDate)),
62+
NullType::ChronoNaiveDateTime => query.bind(none(Value::ChronoNaiveDateTime)),
63+
NullType::ChronoDateTime => query.bind(none(Value::ChronoDateTime)),
5964

60-
NullType::TimeDate => query.bind(None::<Date>),
61-
NullType::TimeTime => query.bind(None::<Time>),
62-
NullType::TimeOffsetDateTime => query.bind(None::<OffsetDateTime>),
63-
NullType::TimePrimitiveDateTime => query.bind(None::<PrimitiveDateTime>),
65+
NullType::TimeDate => query.bind(none(Value::TimeDate)),
66+
NullType::TimeTime => query.bind(none(Value::TimeTime)),
67+
NullType::TimeOffsetDateTime => query.bind(none(Value::TimeOffsetDateTime)),
68+
NullType::TimePrimitiveDateTime => query.bind(none(Value::TimePrimitiveDateTime)),
6469

65-
NullType::Uuid => query.bind(None::<Uuid>),
70+
NullType::Uuid => query.bind(none(Value::Uuid)),
6671
NullType::UuidHyphenated => query.bind(None::<String>),
6772
NullType::UuidSimple => query.bind(None::<String>),
6873

69-
NullType::JsonValue => query.bind(None::<Json<()>>),
74+
NullType::JsonValue => query.bind(none(Value::JsonValue)),
75+
76+
#[cfg(feature = "postgres-only")]
77+
NullType::MacAddress => query.bind(none(Value::MacAddress)),
78+
#[cfg(feature = "postgres-only")]
79+
NullType::IpNetwork => query.bind(none(Value::IpNetwork)),
80+
#[cfg(feature = "postgres-only")]
81+
NullType::BitVec => query.bind(none(Value::BitVec)),
7082
},
7183
}
7284
}
85+
86+
/// Little helper hack to avoid using naming the types
87+
fn none<'a, T, F>(_value_variant: F) -> Option<T>
88+
where
89+
F: Fn(T) -> Value<'a>,
90+
Option<T>: 'a + Send + AnyEncode<'a> + AnyType,
91+
{
92+
None
93+
}

0 commit comments

Comments
 (0)