Support TSRANGE[] and TSTZRANGE[]
This commit is contained in:
parent
a74834896a
commit
5f669f2e05
@ -306,6 +306,10 @@ types. The driver currently supports the following conversions:
|
||||
<td>types::array::ArrayBase<Option<types::range::Range<i32>>></td>
|
||||
<td>INT4RANGE[], INT4RANGE[][], ...</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>types::array::ArrayBase<Option<types::range::Range<extra::time::Timespec>>></td>
|
||||
<td>TSRANGE[], TSTZRANGE[], TSRANGE[][], ...</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>std::hashmap::HashMap<~str, Option<~str>></td>
|
||||
<td>HSTORE</td>
|
||||
|
18
test.rs
18
test.rs
@ -514,6 +514,7 @@ fn test_uuidarray_params() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(travis))]
|
||||
fn test_int4rangearray_params() {
|
||||
test_array_params!("INT4RANGE",
|
||||
Range::new(None, None), "\"(,)\"",
|
||||
@ -521,6 +522,23 @@ fn test_int4rangearray_params() {
|
||||
Range::new(None, Some(RangeBound::new(10i32, Exclusive))), "\"(,10)\"");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tsrangearray_params() {
|
||||
fn make_check<'a>(time: &'a str) -> (Timespec, &'a str) {
|
||||
(time::strptime(time, "%Y-%m-%d").unwrap().to_timespec(), time)
|
||||
}
|
||||
let (v1, s1) = make_check("1970-10-11");
|
||||
let (v2, s2) = make_check("1990-01-01");
|
||||
let r1 = Range::new(None, None);
|
||||
let rs1 = "\"(,)\"";
|
||||
let r2 = Range::new(Some(RangeBound::new(v1, Inclusive)), None);
|
||||
let rs2 = "\"[" + s1 + ",)\"";
|
||||
let r3 = Range::new(None, Some(RangeBound::new(v2, Exclusive)));
|
||||
let rs3 = "\"(," + s2 + ")\"";
|
||||
test_array_params!("TSRANGE", r1, rs1, r2, rs2, r3, rs3);
|
||||
test_array_params!("TSTZRANGE", r1, rs1, r2, rs2, r3, rs3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hstore_params() {
|
||||
macro_rules! make_map(
|
||||
|
10
types/mod.rs
10
types/mod.rs
@ -54,7 +54,9 @@ static UUIDARRAYOID: Oid = 2951;
|
||||
static INT4RANGEOID: Oid = 3904;
|
||||
static INT4RANGEARRAYOID: Oid = 3905;
|
||||
static TSRANGEOID: Oid = 3908;
|
||||
static TSRANGEARRAYOID: Oid = 3909;
|
||||
static TSTZRANGEOID: Oid = 3910;
|
||||
static TSTZRANGEARRAYOID: Oid = 3911;
|
||||
static INT8RANGEOID: Oid = 3926;
|
||||
|
||||
static USEC_PER_SEC: i64 = 1_000_000;
|
||||
@ -194,8 +196,12 @@ make_postgres_type!(
|
||||
INT8RANGEOID => PgInt8Range,
|
||||
#[doc="TSRANGE"]
|
||||
TSRANGEOID => PgTsRange,
|
||||
#[doc="TSRANGE[]"]
|
||||
TSRANGEARRAYOID => PgTsRangeArray member PgTsRange,
|
||||
#[doc="TSTZRANGE"]
|
||||
TSTZRANGEOID => PgTstzRange
|
||||
TSTZRANGEOID => PgTstzRange,
|
||||
#[doc="TSTZRANGE[]"]
|
||||
TSTZRANGEARRAYOID => PgTstzRangeArray member PgTstzRange
|
||||
)
|
||||
|
||||
/// The wire format of a Postgres value
|
||||
@ -426,6 +432,7 @@ from_array_impl!(PgFloat4Array, f32)
|
||||
from_array_impl!(PgFloat8Array, f64)
|
||||
from_array_impl!(PgUuidArray, Uuid)
|
||||
from_array_impl!(PgInt4RangeArray, Range<i32>)
|
||||
from_array_impl!(PgTsRangeArray | PgTstzRangeArray, Range<Timespec>)
|
||||
|
||||
from_map_impl!(PgUnknownType { name: ~"hstore", .. },
|
||||
HashMap<~str, Option<~str>>, |buf| {
|
||||
@ -707,6 +714,7 @@ to_array_impl!(PgFloat4Array, f32)
|
||||
to_array_impl!(PgFloat8Array, f64)
|
||||
to_array_impl!(PgUuidArray, Uuid)
|
||||
to_array_impl!(PgInt4RangeArray, Range<i32>)
|
||||
to_array_impl!(PgTsRangeArray | PgTstzRangeArray, Range<Timespec>)
|
||||
|
||||
impl<'self> ToSql for HashMap<~str, Option<~str>> {
|
||||
fn to_sql(&self, ty: &PostgresType) -> (Format, Option<~[u8]>) {
|
||||
|
Loading…
Reference in New Issue
Block a user