diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index c4924884..a536cbd6 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Steven Fackler "] [dependencies] -phf_codegen = "0.7.22" -regex = "0.1" +phf_codegen = "0.8" +regex = "1.3.1" marksman_escape = "0.1" -linked-hash-map = "0.4" +linked-hash-map = "0.5" diff --git a/codegen/src/sqlstate.rs b/codegen/src/sqlstate.rs index 3d7a6143..79a69638 100644 --- a/codegen/src/sqlstate.rs +++ b/codegen/src/sqlstate.rs @@ -82,17 +82,15 @@ fn make_consts(codes: &LinkedHashMap>, file: &mut BufWriter< } fn make_map(codes: &LinkedHashMap>, file: &mut BufWriter) { - write!( - file, - " -#[rustfmt::skip] -static SQLSTATE_MAP: phf::Map<&'static str, SqlState> = " - ) - .unwrap(); let mut builder = phf_codegen::Map::new(); for (code, names) in codes { builder.entry(&**code, &format!("SqlState::{}", &names[0])); } - builder.build(file).unwrap(); - writeln!(file, ";").unwrap(); + write!( + file, + " +#[rustfmt::skip] +static SQLSTATE_MAP: phf::Map<&'static str, SqlState> = \n{};\n", + builder.build() + ).unwrap(); } diff --git a/postgres-protocol/Cargo.toml b/postgres-protocol/Cargo.toml index bb34c0a9..13d13c43 100644 --- a/postgres-protocol/Cargo.toml +++ b/postgres-protocol/Cargo.toml @@ -13,10 +13,10 @@ base64 = "0.10" byteorder = "1.0" bytes = "0.4" fallible-iterator = "0.2" -generic-array = "0.12" +generic-array = "0.13" hmac = "0.7" md5 = "0.6" memchr = "2.0" -rand = "0.6" +rand = "0.7" sha2 = "0.8" stringprep = "0.1" diff --git a/postgres-types/Cargo.toml b/postgres-types/Cargo.toml index 6026ea6f..7ce39362 100644 --- a/postgres-types/Cargo.toml +++ b/postgres-types/Cargo.toml @@ -18,6 +18,7 @@ with-eui48-0_4 = ["eui48-04"] with-geo-types-0_4 = ["geo-types-04"] with-serde_json-1 = ["serde-1", "serde_json-1"] with-uuid-0_7 = ["uuid-07"] +with-uuid-0_8 = ["uuid-08"] [dependencies] bytes = "0.4" @@ -32,3 +33,4 @@ geo-types-04 = { version = "0.4", package = "geo-types", optional = true } serde-1 = { version = "1.0", package = "serde", optional = true } serde_json-1 = { version = "1.0", package = "serde_json", optional = true } uuid-07 = { version = "0.7", package = "uuid", optional = true } +uuid-08 = { version = "0.8", package = "uuid", optional = true } diff --git a/postgres-types/src/lib.rs b/postgres-types/src/lib.rs index 264442b3..79144546 100644 --- a/postgres-types/src/lib.rs +++ b/postgres-types/src/lib.rs @@ -200,6 +200,8 @@ mod geo_types_04; mod serde_json_1; #[cfg(feature = "with-uuid-0_7")] mod uuid_07; +#[cfg(feature = "with-uuid-0_8")] +mod uuid_08; #[doc(hidden)] pub mod private; diff --git a/postgres-types/src/uuid_08.rs b/postgres-types/src/uuid_08.rs new file mode 100644 index 00000000..72d5e82f --- /dev/null +++ b/postgres-types/src/uuid_08.rs @@ -0,0 +1,25 @@ +use bytes::BytesMut; +use postgres_protocol::types; +use std::error::Error; +use uuid_08::Uuid; + +use crate::{FromSql, IsNull, ToSql, Type}; + +impl<'a> FromSql<'a> for Uuid { + fn from_sql(_: &Type, raw: &[u8]) -> Result> { + let bytes = types::uuid_from_sql(raw)?; + Ok(Uuid::from_bytes(bytes)) + } + + accepts!(UUID); +} + +impl ToSql for Uuid { + fn to_sql(&self, _: &Type, w: &mut BytesMut) -> Result> { + types::uuid_to_sql(*self.as_bytes(), w); + Ok(IsNull::No) + } + + accepts!(UUID); + to_sql_checked!(); +} diff --git a/postgres/CHANGELOG.md b/postgres/CHANGELOG.md index 9cd1801b..1e25bf5b 100644 --- a/postgres/CHANGELOG.md +++ b/postgres/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## Unreleased + +### Added +* Added support for converting to and from `uuid` crate v0.8 + ## v0.17.0-alpha.1 - 2019-10-14 ### Changed diff --git a/postgres/Cargo.toml b/postgres/Cargo.toml index e75ed449..2e9726e0 100644 --- a/postgres/Cargo.toml +++ b/postgres/Cargo.toml @@ -26,6 +26,7 @@ with-eui48-0_4 = ["tokio-postgres/with-eui48-0_4"] with-geo-types-0_4 = ["tokio-postgres/with-geo-types-0_4"] with-serde_json-1 = ["tokio-postgres/with-serde_json-1"] with-uuid-0_7 = ["tokio-postgres/with-uuid-0_7"] +with-uuid-0_8 = ["tokio-postgres/with-uuid-0_8"] [dependencies] bytes = "0.4" diff --git a/tokio-postgres/CHANGELOG.md b/tokio-postgres/CHANGELOG.md index 7ed4b4de..51a3bf8b 100644 --- a/tokio-postgres/CHANGELOG.md +++ b/tokio-postgres/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## Unreleased + +### Added +* Added support for converting to and from `uuid` crate v0.8 + ## v0.5.0-alpha.1 - 2019-10-14 ### Changed diff --git a/tokio-postgres/Cargo.toml b/tokio-postgres/Cargo.toml index 40f62a17..f255cab4 100644 --- a/tokio-postgres/Cargo.toml +++ b/tokio-postgres/Cargo.toml @@ -33,6 +33,7 @@ with-eui48-0_4 = ["postgres-types/with-eui48-0_4"] with-geo-types-0_4 = ["postgres-types/with-geo-types-0_4"] with-serde_json-1 = ["postgres-types/with-serde_json-1"] with-uuid-0_7 = ["postgres-types/with-uuid-0_7"] +with-uuid-0_8 = ["postgres-types/with-uuid-0_8"] [dependencies] bytes = "0.4" @@ -40,16 +41,16 @@ fallible-iterator = "0.2" futures-preview = { version = "=0.3.0-alpha.19", features = ["async-await"] } log = "0.4" parking_lot = "0.9" -percent-encoding = "1.0" +percent-encoding = "2.0" pin-project = "0.4" -phf = "0.7.23" +phf = "0.8" postgres-protocol = { version = "=0.5.0-alpha.1", path = "../postgres-protocol" } postgres-types = { version = "=0.1.0-alpha.1", path = "../postgres-types" } tokio = { version = "=0.2.0-alpha.6", default-features = false, features = ["io", "codec"] } [dev-dependencies] tokio = "=0.2.0-alpha.6" -env_logger = "0.5" +env_logger = "0.7" criterion = "0.3" bit-vec-06 = { version = "0.6", package = "bit-vec" } @@ -59,3 +60,5 @@ geo-types-04 = { version = "0.4", package = "geo-types" } serde-1 = { version = "1.0", package = "serde" } serde_json-1 = { version = "1.0", package = "serde_json" } uuid-07 = { version = "0.7", package = "uuid" } +uuid-08 = { version = "0.8", package = "uuid" } + diff --git a/tokio-postgres/tests/test/types/mod.rs b/tokio-postgres/tests/test/types/mod.rs index 3daabcd8..8d411d54 100644 --- a/tokio-postgres/tests/test/types/mod.rs +++ b/tokio-postgres/tests/test/types/mod.rs @@ -24,6 +24,8 @@ mod geo_010; mod serde_json_1; #[cfg(feature = "with-uuid-0_7")] mod uuid_07; +#[cfg(feature = "with-uuid-0_8")] +mod uuid_08; async fn test_type(sql_type: &str, checks: &[(T, S)]) where diff --git a/tokio-postgres/tests/test/types/uuid_08.rs b/tokio-postgres/tests/test/types/uuid_08.rs new file mode 100644 index 00000000..01b674b9 --- /dev/null +++ b/tokio-postgres/tests/test/types/uuid_08.rs @@ -0,0 +1,18 @@ +use uuid_08::Uuid; + +use crate::types::test_type; + +#[tokio::test] +async fn test_uuid_params() { + test_type( + "UUID", + &[ + ( + Some(Uuid::parse_str("a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11").unwrap()), + "'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'", + ), + (None, "NULL"), + ], + ) + .await +}