Upgrade type crate versions
Also add the version number to the feature name. This both makes it more obvious when using them and opens the window for support of multiple versions simultaneously in the future.
This commit is contained in:
@@ -7,14 +7,12 @@ description = "Internal crate used by postgres and postgres-tokio"
|
||||
repository = "https://github.com/sfackler/rust-postgres"
|
||||
|
||||
[features]
|
||||
with-bit-vec = ["bit-vec"]
|
||||
with-chrono = ["chrono"]
|
||||
with-eui48 = ["eui48"]
|
||||
with-geo = ["geo"]
|
||||
with-rustc-serialize = ["rustc-serialize"]
|
||||
with-serde_json = ["serde_json"]
|
||||
with-time = ["time"]
|
||||
with-uuid = ["uuid"]
|
||||
"with-bit-vec-0.5" = ["bit-vec"]
|
||||
"with-chrono-0.4" = ["chrono"]
|
||||
"with-eui48-0.3" = ["eui48"]
|
||||
"with-geo-0.8" = ["geo"]
|
||||
with-serde_json-1 = ["serde_json"]
|
||||
"with-uuid-0.6" = ["uuid"]
|
||||
|
||||
[dependencies]
|
||||
hex = "0.3"
|
||||
@@ -22,11 +20,9 @@ fallible-iterator = "0.1.3"
|
||||
phf = "=0.7.21"
|
||||
postgres-protocol = { version = "0.3", path = "../postgres-protocol" }
|
||||
|
||||
bit-vec = { version = "0.4", optional = true }
|
||||
bit-vec = { version = "0.5", optional = true }
|
||||
chrono = { version = "0.4", optional = true }
|
||||
eui48 = { version = "0.3", optional = true }
|
||||
geo = { version = "0.4", optional = true }
|
||||
rustc-serialize = { version = "0.3", optional = true }
|
||||
geo = { version = "0.8", optional = true }
|
||||
serde_json = { version = "1.0", optional = true }
|
||||
time = { version = "0.1.14", optional = true }
|
||||
uuid = { version = "0.5", optional = true }
|
||||
uuid = { version = "0.6", optional = true }
|
||||
|
||||
@@ -65,21 +65,17 @@ where
|
||||
v.to_sql(ty, out)
|
||||
}
|
||||
|
||||
#[cfg(feature = "with-bit-vec")]
|
||||
#[cfg(feature = "with-bit-vec-0.5")]
|
||||
mod bit_vec;
|
||||
#[cfg(feature = "with-chrono")]
|
||||
#[cfg(feature = "with-chrono-0.4")]
|
||||
mod chrono;
|
||||
#[cfg(feature = "with-eui48")]
|
||||
#[cfg(feature = "with-eui48-0.3")]
|
||||
mod eui48;
|
||||
#[cfg(feature = "with-geo")]
|
||||
#[cfg(feature = "with-geo-0.8")]
|
||||
mod geo;
|
||||
#[cfg(feature = "with-rustc-serialize")]
|
||||
mod rustc_serialize;
|
||||
#[cfg(feature = "with-serde_json")]
|
||||
#[cfg(feature = "with-serde_json-1")]
|
||||
mod serde_json;
|
||||
#[cfg(feature = "with-time")]
|
||||
mod time;
|
||||
#[cfg(feature = "with-uuid")]
|
||||
#[cfg(feature = "with-uuid-0.6")]
|
||||
mod uuid;
|
||||
|
||||
mod special;
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
extern crate rustc_serialize;
|
||||
|
||||
use self::rustc_serialize::json;
|
||||
use std::error::Error;
|
||||
use std::io::{Read, Write};
|
||||
|
||||
use types::{FromSql, IsNull, ToSql, Type};
|
||||
|
||||
impl<'a> FromSql<'a> for json::Json {
|
||||
fn from_sql(ty: &Type, mut raw: &[u8]) -> Result<json::Json, Box<Error + Sync + Send>> {
|
||||
if *ty == Type::JSONB {
|
||||
let mut b = [0; 1];
|
||||
raw.read_exact(&mut b)?;
|
||||
// We only support version 1 of the jsonb binary format
|
||||
if b[0] != 1 {
|
||||
return Err("unsupported JSONB encoding version".into());
|
||||
}
|
||||
}
|
||||
json::Json::from_reader(&mut raw).map_err(Into::into)
|
||||
}
|
||||
|
||||
accepts!(JSON, JSONB);
|
||||
}
|
||||
|
||||
impl ToSql for json::Json {
|
||||
fn to_sql(&self, ty: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
|
||||
if *ty == Type::JSONB {
|
||||
out.push(1);
|
||||
}
|
||||
write!(out, "{}", self)?;
|
||||
Ok(IsNull::No)
|
||||
}
|
||||
|
||||
accepts!(JSON, JSONB);
|
||||
to_sql_checked!();
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
extern crate time;
|
||||
|
||||
use self::time::Timespec;
|
||||
use postgres_protocol::types;
|
||||
use std::error::Error;
|
||||
|
||||
use types::{FromSql, IsNull, ToSql, Type};
|
||||
|
||||
const USEC_PER_SEC: i64 = 1_000_000;
|
||||
const NSEC_PER_USEC: i64 = 1_000;
|
||||
|
||||
// Number of seconds from 1970-01-01 to 2000-01-01
|
||||
const TIME_SEC_CONVERSION: i64 = 946684800;
|
||||
|
||||
impl<'a> FromSql<'a> for Timespec {
|
||||
fn from_sql(_: &Type, raw: &[u8]) -> Result<Timespec, Box<Error + Sync + Send>> {
|
||||
let t = types::timestamp_from_sql(raw)?;
|
||||
let mut sec = t / USEC_PER_SEC + TIME_SEC_CONVERSION;
|
||||
let mut usec = t % USEC_PER_SEC;
|
||||
|
||||
if usec < 0 {
|
||||
sec -= 1;
|
||||
usec = USEC_PER_SEC + usec;
|
||||
}
|
||||
|
||||
Ok(Timespec::new(sec, (usec * NSEC_PER_USEC) as i32))
|
||||
}
|
||||
|
||||
accepts!(TIMESTAMP, TIMESTAMPTZ);
|
||||
}
|
||||
|
||||
impl ToSql for Timespec {
|
||||
fn to_sql(&self, _: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
|
||||
let t = (self.sec - TIME_SEC_CONVERSION) * USEC_PER_SEC + self.nsec as i64 / NSEC_PER_USEC;
|
||||
types::timestamp_to_sql(t, w);
|
||||
Ok(IsNull::No)
|
||||
}
|
||||
|
||||
accepts!(TIMESTAMP, TIMESTAMPTZ);
|
||||
to_sql_checked!();
|
||||
}
|
||||
Reference in New Issue
Block a user