Skip to content

Commit 95f901a

Browse files
committed
Update to postgres 0.17, refactor chrono support, drop time support
- Updates integration and tests to postgres 0.17 - Moves chrono crate support to "with-chrono-0_4" to match postgres crate - Drops time crate support since it was dropped in postgres crate
1 parent 3e66a77 commit 95f901a

File tree

4 files changed

+60
-77
lines changed

4 files changed

+60
-77
lines changed

‎Cargo.toml‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ repository = "https://github.com/sfackler/rust-postgres-range"
88
documentation = "https://sfackler.github.io/rust-postgres-range/doc/v0.9.0/postgres_range"
99

1010
[features]
11-
with-time = ["time", "postgres-shared/with-time"]
12-
with-chrono = ["chrono", "postgres-shared/with-chrono"]
11+
with-chrono-0_4 = ["chrono-04", "postgres-types/with-chrono-0_4"]
1312

1413
[dependencies]
15-
time ={version = "0.1", optional = true }
16-
postgres-protocol = "0.3"
17-
chrono ={version = "0.4.0", optional = true }
18-
postgres-shared = "0.4.0"
14+
postgres-protocol = "0.5"
15+
postgres-types = "0.1"
16+
chrono-04 ={version = "0.4", package = "chrono", optional = true }
1917

2018
[dev-dependencies]
21-
postgres ={version = "0.15", features = ["with-time"] }
19+
postgres ={version = "0.17" }

‎src/chrono_04.rs‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use chrono_04::{DateTime,NaiveDateTime,TimeZone};
2+
3+
usecrate::{Normalizable,RangeBound,BoundSided};
4+
5+
impl<T>NormalizableforDateTime<T>
6+
whereT:TimeZone{
7+
fnnormalize<S>(bound:RangeBound<S,DateTime<T>>) -> RangeBound<S,DateTime<T>>
8+
where
9+
S:BoundSided,
10+
{
11+
bound
12+
}
13+
}
14+
15+
implNormalizableforNaiveDateTime
16+
{
17+
fnnormalize<S>(bound:RangeBound<S,NaiveDateTime>) -> RangeBound<S,NaiveDateTime>
18+
where
19+
S:BoundSided,
20+
{
21+
bound
22+
}
23+
}

‎src/impls.rs‎

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
use std::error::Error;
2-
use postgres_shared::types::{FromSql,IsNull,Kind,ToSql,Type};
2+
use postgres_types::{FromSql,IsNull,Kind,ToSql,Type};
3+
use postgres_types::private::BytesMut;
34
use postgres_protocol::{selfas protocol, types};
45

56
use{BoundSided,BoundType,Normalizable,Range,RangeBound};
67

7-
impl<T>FromSqlforRange<T>
8+
impl<'a,T>FromSql<'a>forRange<T>
89
where
9-
T:PartialOrd + Normalizable + FromSql,
10+
T:PartialOrd + Normalizable + FromSql<'a>,
1011
{
11-
fnfrom_sql(ty:&Type,raw:&[u8]) -> Result<Range<T>,Box<Error + Sync + Send>>{
12+
fnfrom_sql(ty:&Type,raw:&'a[u8]) -> Result<Range<T>,Box<dynError + Sync + Send>>{
1213
let element_type = match ty.kind(){
1314
&Kind::Range(ref ty) => ty,
1415
_ => panic!("unexpected type{:?}", ty),
@@ -32,9 +33,9 @@ where
3233
}
3334
}
3435

35-
fnbound_from_sql<T,S>(bound: types::RangeBound<Option<&[u8]>>,ty:&Type) -> Result<Option<RangeBound<S,T>>,Box<Error + Sync + Send>>
36+
fnbound_from_sql<'a,T,S>(bound: types::RangeBound<Option<&'a[u8]>>,ty:&Type) -> Result<Option<RangeBound<S,T>>,Box<dynError + Sync + Send>>
3637
where
37-
T:PartialOrd + Normalizable + FromSql,
38+
T:PartialOrd + Normalizable + FromSql<'a>,
3839
S:BoundSided,
3940
{
4041
match bound {
@@ -60,7 +61,7 @@ impl<T> ToSql for Range<T>
6061
where
6162
T:PartialOrd + Normalizable + ToSql,
6263
{
63-
fnto_sql(&self,ty:&Type,buf:&mutVec<u8>) -> Result<IsNull,Box<Error + Sync + Send>>{
64+
fnto_sql(&self,ty:&Type,buf:&mutBytesMut) -> Result<IsNull,Box<dynError + Sync + Send>>{
6465
let element_type = match ty.kind(){
6566
&Kind::Range(ref ty) => ty,
6667
_ => panic!("unexpected type{:?}", ty),
@@ -89,7 +90,7 @@ where
8990
to_sql_checked!();
9091
}
9192

92-
fnbound_to_sql<S,T>(bound:Option<&RangeBound<S,T>>,ty:&Type,buf:&mutVec<u8>) -> Result<types::RangeBound<protocol::IsNull>,Box<Error + Sync + Send>>
93+
fnbound_to_sql<S,T>(bound:Option<&RangeBound<S,T>>,ty:&Type,buf:&mutBytesMut) -> Result<types::RangeBound<protocol::IsNull>,Box<dynError + Sync + Send>>
9394
where
9495
S:BoundSided,
9596
T:ToSql,
@@ -114,10 +115,10 @@ where
114115
mod test {
115116
use std::fmt;
116117

117-
use postgres::{Connection,TlsMode};
118+
use postgres::{Client,NoTls};
118119
use postgres::types::{FromSql,ToSql};
119-
#[cfg(feature = "with-time")]
120-
usetime::{self,Timespec};
120+
#[cfg(feature = "with-chrono-0_4")]
121+
usechrono_04::{TimeZone,Utc,Duration};
121122

122123
macro_rules! test_range {
123124
($name:expr, $t:ty, $low:expr, $low_str:expr, $high:expr, $high_str:expr) => ({
@@ -140,16 +141,21 @@ mod test{
140141
})
141142
}
142143

143-
fntest_type<T:PartialEq + FromSql + ToSql,S: fmt::Display>(sql_type:&str,checks:&[(T,S)]){
144-
let conn = Connection::connect("postgres://postgres@localhost",TlsMode::None).unwrap();
144+
145+
fntest_type<T,S>(sql_type:&str,checks:&[(T,S)])
146+
wherefor<'a>
147+
T:Sync + PartialEq + FromSql<'a> + ToSql,
148+
S: fmt::Display
149+
{
150+
letmut conn = Client::connect("postgres://postgres@localhost",NoTls).unwrap();
145151
for&(ref val,ref repr)in checks {
146152
let stmt = conn.prepare(&*format!("SELECT{}::{}",*repr, sql_type))
147153
.unwrap();
148-
let result = stmt.query(&[]).unwrap().iter().next().unwrap().get(0);
154+
let result = conn.query(&stmt,&[]).unwrap().iter().next().unwrap().get(0);
149155
assert!(val == &result);
150156

151157
let stmt = conn.prepare(&*format!("SELECT $1::{}", sql_type)).unwrap();
152-
let result = stmt.query(&[val]).unwrap().iter().next().unwrap().get(0);
158+
let result = conn.query(&stmt,&[val]).unwrap().iter().next().unwrap().get(0);
153159
assert!(val == &result);
154160
}
155161
}
@@ -164,25 +170,19 @@ mod test{
164170
test_range!("INT8RANGE",i64,100i64,"100",200i64,"200")
165171
}
166172

167-
#[cfg(feature = "with-time")]
168-
fntest_timespec_range_params(sql_type:&str){
169-
fnt(time:&str) -> Timespec{
170-
time::strptime(time,"%Y-%m-%d").unwrap().to_timespec()
171-
}
172-
let low = "1970-01-01";
173-
let high = "1980-01-01";
174-
test_range!(sql_type,Timespec, t(low), low, t(high), high);
175-
}
176-
177173
#[test]
178-
#[cfg(feature = "with-time")]
174+
#[cfg(feature = "with-chrono-0_4")]
179175
fntest_tsrange_params(){
180-
test_timespec_range_params("TSRANGE");
176+
let low = Utc.timestamp(0,0);
177+
let high = low + Duration::days(10);
178+
test_range!("TSRANGE",NaiveDateTime, low.naive_utc(),"1970-01-01", high.naive_utc(),"1970-01-11");
181179
}
182180

183181
#[test]
184-
#[cfg(feature = "with-time")]
182+
#[cfg(feature = "with-chrono-0_4")]
185183
fntest_tstzrange_params(){
186-
test_timespec_range_params("TSTZRANGE");
184+
let low = Utc.timestamp(0,0);
185+
let high = low + Duration::days(10);
186+
test_range!("TSTZRANGE",DateTime<Utc>, low,"1970-01-01", high,"1970-01-11");
187187
}
188188
}

‎src/lib.rs‎

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,19 @@
33

44
externcrate postgres_protocol;
55
#[macro_use(to_sql_checked)]
6-
externcratepostgres_shared;
6+
externcratepostgres_types;
77

8-
#[cfg(feature = "with-time")]
9-
externcrate time;
10-
#[cfg(feature = "with-chrono")]
11-
externcrate chrono;
8+
#[cfg(feature = "with-chrono-0_4")]
9+
mod chrono_04;
1210

1311
#[cfg(test)]
1412
externcrate postgres;
1513

16-
#[cfg(feature = "with-chrono")]
17-
use chrono::{DateTime,NaiveDateTime,TimeZone};
1814
use std::cmp::Ordering;
1915
use std::fmt;
2016
use std::i32;
2117
use std::i64;
2218
use std::marker::PhantomData;
23-
#[cfg(feature = "with-time")]
24-
use time::Timespec;
2519

2620
useBoundSide::{Lower,Upper};
2721
useBoundType::{Exclusive,Inclusive};
@@ -155,38 +149,6 @@ macro_rules! bounded_normalizable{
155149
bounded_normalizable!(i32);
156150
bounded_normalizable!(i64);
157151

158-
#[cfg(feature = "with-time")]
159-
implNormalizableforTimespec{
160-
fnnormalize<S>(bound:RangeBound<S,Timespec>) -> RangeBound<S,Timespec>
161-
where
162-
S:BoundSided,
163-
{
164-
bound
165-
}
166-
}
167-
168-
#[cfg(feature = "with-chrono")]
169-
impl<T>NormalizableforDateTime<T>
170-
whereT:TimeZone{
171-
fnnormalize<S>(bound:RangeBound<S,DateTime<T>>) -> RangeBound<S,DateTime<T>>
172-
where
173-
S:BoundSided,
174-
{
175-
bound
176-
}
177-
}
178-
179-
#[cfg(feature = "with-chrono")]
180-
implNormalizableforNaiveDateTime
181-
{
182-
fnnormalize<S>(bound:RangeBound<S,NaiveDateTime>) -> RangeBound<S,NaiveDateTime>
183-
where
184-
S:BoundSided,
185-
{
186-
bound
187-
}
188-
}
189-
190152
/// The possible sides of a bound.
191153
#[derive(Debug,PartialEq,Eq,Clone,Copy)]
192154
pubenumBoundSide{

0 commit comments

Comments
(0)