diff --git a/postgres-shared/Cargo.toml b/postgres-shared/Cargo.toml index fc73a0a9..65ed5346 100644 --- a/postgres-shared/Cargo.toml +++ b/postgres-shared/Cargo.toml @@ -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 } diff --git a/postgres-shared/src/types/mod.rs b/postgres-shared/src/types/mod.rs index bf3e69e9..cfa29ee1 100644 --- a/postgres-shared/src/types/mod.rs +++ b/postgres-shared/src/types/mod.rs @@ -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; diff --git a/postgres-shared/src/types/rustc_serialize.rs b/postgres-shared/src/types/rustc_serialize.rs deleted file mode 100644 index 6df046e1..00000000 --- a/postgres-shared/src/types/rustc_serialize.rs +++ /dev/null @@ -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> { - 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) -> Result> { - if *ty == Type::JSONB { - out.push(1); - } - write!(out, "{}", self)?; - Ok(IsNull::No) - } - - accepts!(JSON, JSONB); - to_sql_checked!(); -} diff --git a/postgres-shared/src/types/time.rs b/postgres-shared/src/types/time.rs deleted file mode 100644 index f042ce7d..00000000 --- a/postgres-shared/src/types/time.rs +++ /dev/null @@ -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> { - 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) -> Result> { - 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!(); -} diff --git a/postgres/Cargo.toml b/postgres/Cargo.toml index edebfe92..be135730 100644 --- a/postgres/Cargo.toml +++ b/postgres/Cargo.toml @@ -12,14 +12,12 @@ categories = ["database"] [package.metadata.docs.rs] features = [ - "with-bit-vec", - "with-chrono", - "with-eui48", - "with-geo", - "with-rustc-serialize", - "with-serde_json", - "with-time", - "with-uuid", + "with-bit-vec-0.5", + "with-chrono-0.4", + "with-eui48-0.3", + "with-geo-0.8", + "with-serde_json-1", + "with-uuid-0.6", "with-openssl", "with-native-tls", ] @@ -38,14 +36,12 @@ name = "test" path = "tests/test.rs" [features] -with-bit-vec = ["postgres-shared/with-bit-vec"] -with-chrono = ["postgres-shared/with-chrono"] -with-eui48 = ["postgres-shared/with-eui48"] -with-geo = ["postgres-shared/with-geo"] -with-rustc-serialize = ["postgres-shared/with-rustc-serialize"] -with-serde_json = ["postgres-shared/with-serde_json"] -with-time = ["postgres-shared/with-time"] -with-uuid = ["postgres-shared/with-uuid"] +"with-bit-vec-0.5" = ["postgres-shared/with-bit-vec-0.5"] +"with-chrono-0.4" = ["postgres-shared/with-chrono-0.4"] +"with-eui48-0.3" = ["postgres-shared/with-eui48-0.3"] +"with-geo-0.8" = ["postgres-shared/with-geo-0.8"] +"with-serde_json-1" = ["postgres-shared/with-serde_json-1"] +"with-uuid-0.6" = ["postgres-shared/with-uuid-0.6"] with-openssl = ["openssl"] with-native-tls = ["native-tls"] @@ -62,7 +58,6 @@ socket2 = { version = "0.3.5", features = ["unix"] } openssl = { version = "0.9.23", optional = true } native-tls = { version = "0.1", optional = true } -rustc-serialize = { version = "0.3", optional = true } schannel = { version = "0.1", optional = true } security-framework = { version = "0.1.2", optional = true } @@ -73,11 +68,9 @@ postgres-shared = { version = "0.4.1", path = "../postgres-shared" } hex = "0.3" url = "1.0" -bit-vec = "0.4" +bit-vec = "0.5" chrono = "0.4" eui48 = "0.3" -geo = "0.4" -rustc-serialize = "0.3" +geo = "0.8" serde_json = "1.0" -time = "0.1.14" -uuid = "0.5" +uuid = "0.6" diff --git a/postgres/tests/types/mod.rs b/postgres/tests/types/mod.rs index 86974fd6..92192246 100644 --- a/postgres/tests/types/mod.rs +++ b/postgres/tests/types/mod.rs @@ -8,21 +8,17 @@ use std::result; use postgres::types::{FromSql, FromSqlOwned, IsNull, Kind, ToSql, Type, WrongType}; use postgres::{Connection, TlsMode}; -#[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; fn test_type(sql_type: &str, checks: &[(T, S)]) diff --git a/postgres/tests/types/rustc_serialize.rs b/postgres/tests/types/rustc_serialize.rs deleted file mode 100644 index 646cf9d0..00000000 --- a/postgres/tests/types/rustc_serialize.rs +++ /dev/null @@ -1,41 +0,0 @@ -extern crate rustc_serialize; - -use self::rustc_serialize::json::Json; - -use types::test_type; - -#[test] -fn test_json_params() { - test_type( - "JSON", - &[ - ( - Some(Json::from_str("[10, 11, 12]").unwrap()), - "'[10, 11, 12]'", - ), - ( - Some(Json::from_str("{\"f\": \"asd\"}").unwrap()), - "'{\"f\": \"asd\"}'", - ), - (None, "NULL"), - ], - ) -} - -#[test] -fn test_jsonb_params() { - test_type( - "JSONB", - &[ - ( - Some(Json::from_str("[10, 11, 12]").unwrap()), - "'[10, 11, 12]'", - ), - ( - Some(Json::from_str("{\"f\": \"asd\"}").unwrap()), - "'{\"f\": \"asd\"}'", - ), - (None, "NULL"), - ], - ) -} diff --git a/postgres/tests/types/time.rs b/postgres/tests/types/time.rs deleted file mode 100644 index 42539ccc..00000000 --- a/postgres/tests/types/time.rs +++ /dev/null @@ -1,72 +0,0 @@ -extern crate time; - -use self::time::Timespec; -use types::test_type; - -use postgres::types::Timestamp; - -#[test] -fn test_tm_params() { - fn make_check<'a>(time: &'a str) -> (Option, &'a str) { - ( - Some( - time::strptime(time, "'%Y-%m-%d %H:%M:%S.%f'") - .unwrap() - .to_timespec(), - ), - time, - ) - } - test_type( - "TIMESTAMP", - &[ - make_check("'1970-01-01 00:00:00.01'"), - make_check("'1965-09-25 11:19:33.100314'"), - make_check("'2010-02-09 23:11:45.1202'"), - (None, "NULL"), - ], - ); - test_type( - "TIMESTAMP WITH TIME ZONE", - &[ - make_check("'1970-01-01 00:00:00.01'"), - make_check("'1965-09-25 11:19:33.100314'"), - make_check("'2010-02-09 23:11:45.1202'"), - (None, "NULL"), - ], - ); -} - -#[test] -fn test_with_special_tm_params() { - fn make_check<'a>(time: &'a str) -> (Timestamp, &'a str) { - ( - Timestamp::Value( - time::strptime(time, "'%Y-%m-%d %H:%M:%S.%f'") - .unwrap() - .to_timespec(), - ), - time, - ) - } - test_type( - "TIMESTAMP", - &[ - make_check("'1970-01-01 00:00:00.01'"), - make_check("'1965-09-25 11:19:33.100314'"), - make_check("'2010-02-09 23:11:45.1202'"), - (Timestamp::PosInfinity, "'infinity'"), - (Timestamp::NegInfinity, "'-infinity'"), - ], - ); - test_type( - "TIMESTAMP WITH TIME ZONE", - &[ - make_check("'1970-01-01 00:00:00.01'"), - make_check("'1965-09-25 11:19:33.100314'"), - make_check("'2010-02-09 23:11:45.1202'"), - (Timestamp::PosInfinity, "'infinity'"), - (Timestamp::NegInfinity, "'-infinity'"), - ], - ); -} diff --git a/tokio-postgres/Cargo.toml b/tokio-postgres/Cargo.toml index 1c07f6f1..432c048e 100644 --- a/tokio-postgres/Cargo.toml +++ b/tokio-postgres/Cargo.toml @@ -11,14 +11,12 @@ categories = ["database"] [package.metadata.docs.rs] features = [ - "with-bit-vec", - "with-chrono", - "with-eui48", - "with-geo", - "with-rustc-serialize", - "with-serde_json", - "with-time", - "with-uuid", + "with-bit-vec-0.5", + "with-chrono-0.4", + "with-eui48-0.3", + "with-geo-0.8", + "with-serde_json-1", + "with-uuid-0.6", "with-openssl", ] @@ -26,14 +24,12 @@ features = [ circle-ci = { repository = "sfackler/rust-postgres" } [features] -with-bit-vec = ["postgres-shared/with-bit-vec"] -with-chrono = ["postgres-shared/with-chrono"] -with-eui48 = ["postgres-shared/with-eui48"] -with-geo = ["postgres-shared/with-geo"] -with-rustc-serialize = ["postgres-shared/with-rustc-serialize"] -with-serde_json = ["postgres-shared/with-serde_json"] -with-time = ["postgres-shared/with-time"] -with-uuid = ["postgres-shared/with-uuid"] +"with-bit-vec-0.5" = ["postgres-shared/with-bit-vec-0.5"] +"with-chrono-0.4" = ["postgres-shared/with-chrono-0.4"] +"with-eui48-0.3" = ["postgres-shared/with-eui48-0.3"] +"with-geo-0.8" = ["postgres-shared/with-geo-0.8"] +"with-serde_json-1" = ["postgres-shared/with-serde_json-1"] +"with-uuid-0.6" = ["postgres-shared/with-uuid-0.6"] with-openssl = ["tokio-openssl", "openssl"]