Skip to content

Commit a943a0e

Browse files
committed
Support uuid 0.8
1 parent 7a95f6a commit a943a0e

File tree

9 files changed

+63
-0
lines changed

9 files changed

+63
-0
lines changed

postgres-types/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ with-eui48-0_4 = ["eui48-04"]
1818
with-geo-types-0_4 = ["geo-types-04"]
1919
with-serde_json-1 = ["serde-1", "serde_json-1"]
2020
with-uuid-0_7 = ["uuid-07"]
21+
with-uuid-0_8 = ["uuid-08"]
2122

2223
[dependencies]
2324
bytes = "0.4"
@@ -32,3 +33,4 @@ geo-types-04 = { version = "0.4", package = "geo-types", optional = true }
3233
serde-1 = { version = "1.0", package = "serde", optional = true }
3334
serde_json-1 = { version = "1.0", package = "serde_json", optional = true }
3435
uuid-07 = { version = "0.7", package = "uuid", optional = true }
36+
uuid-08 = { version = "0.8", package = "uuid", optional = true }

postgres-types/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ mod geo_types_04;
200200
mod serde_json_1;
201201
#[cfg(feature = "with-uuid-0_7")]
202202
mod uuid_07;
203+
#[cfg(feature = "with-uuid-0_8")]
204+
mod uuid_08;
203205

204206
#[doc(hidden)]
205207
pub mod private;

postgres-types/src/uuid_08.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use bytes::BytesMut;
2+
use postgres_protocol::types;
3+
use std::error::Error;
4+
use uuid_08::Uuid;
5+
6+
use crate::{FromSql, IsNull, ToSql, Type};
7+
8+
impl<'a> FromSql<'a> for Uuid {
9+
fn from_sql(_: &Type, raw: &[u8]) -> Result<Uuid, Box<dyn Error + Sync + Send>> {
10+
let bytes = types::uuid_from_sql(raw)?;
11+
Ok(Uuid::from_bytes(bytes))
12+
}
13+
14+
accepts!(UUID);
15+
}
16+
17+
impl ToSql for Uuid {
18+
fn to_sql(&self, _: &Type, w: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
19+
types::uuid_to_sql(*self.as_bytes(), w);
20+
Ok(IsNull::No)
21+
}
22+
23+
accepts!(UUID);
24+
to_sql_checked!();
25+
}

postgres/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## Unreleased
4+
5+
### Added
6+
* Added support for converting to and from `uuid` crate v0.8
7+
38
## v0.17.0-alpha.1 - 2019-10-14
49

510
### Changed

postgres/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ with-eui48-0_4 = ["tokio-postgres/with-eui48-0_4"]
2626
with-geo-types-0_4 = ["tokio-postgres/with-geo-types-0_4"]
2727
with-serde_json-1 = ["tokio-postgres/with-serde_json-1"]
2828
with-uuid-0_7 = ["tokio-postgres/with-uuid-0_7"]
29+
with-uuid-0_8 = ["tokio-postgres/with-uuid-0_8"]
2930

3031
[dependencies]
3132
bytes = "0.4"

tokio-postgres/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## Unreleased
4+
5+
### Added
6+
* Added support for converting to and from `uuid` crate v0.8
7+
38
## v0.5.0-alpha.1 - 2019-10-14
49

510
### Changed

tokio-postgres/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ with-eui48-0_4 = ["postgres-types/with-eui48-0_4"]
3333
with-geo-types-0_4 = ["postgres-types/with-geo-types-0_4"]
3434
with-serde_json-1 = ["postgres-types/with-serde_json-1"]
3535
with-uuid-0_7 = ["postgres-types/with-uuid-0_7"]
36+
with-uuid-0_8 = ["postgres-types/with-uuid-0_8"]
3637

3738
[dependencies]
3839
bytes = "0.4"
@@ -59,3 +60,5 @@ geo-types-04 = { version = "0.4", package = "geo-types" }
5960
serde-1 = { version = "1.0", package = "serde" }
6061
serde_json-1 = { version = "1.0", package = "serde_json" }
6162
uuid-07 = { version = "0.7", package = "uuid" }
63+
uuid-08 = { version = "0.8", package = "uuid" }
64+

tokio-postgres/tests/test/types/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ mod geo_010;
2424
mod serde_json_1;
2525
#[cfg(feature = "with-uuid-0_7")]
2626
mod uuid_07;
27+
#[cfg(feature = "with-uuid-0_8")]
28+
mod uuid_08;
2729

2830
async fn test_type<T, S>(sql_type: &str, checks: &[(T, S)])
2931
where
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use uuid_08::Uuid;
2+
3+
use crate::types::test_type;
4+
5+
#[tokio::test]
6+
async fn test_uuid_params() {
7+
test_type(
8+
"UUID",
9+
&[
10+
(
11+
Some(Uuid::parse_str("a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11").unwrap()),
12+
"'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'",
13+
),
14+
(None, "NULL"),
15+
],
16+
)
17+
.await
18+
}

0 commit comments

Comments
 (0)