Skip to content

Commit a9c20d9

Browse files
committed
add support for the uuid type on the Any database
1 parent f8be8a8 commit a9c20d9

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

sqlx-core/src/any/types.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,11 @@ mod decimal_types {
151151
impl_any_encode!(Decimal);
152152
impl_any_decode!(Decimal);
153153
}
154+
155+
#[cfg(feature = "uuid")]
156+
mod uuid_types {
157+
use uuid::Uuid;
158+
impl_any_type!(Uuid);
159+
impl_any_encode!(Uuid);
160+
impl_any_decode!(Uuid);
161+
}

tests/any/any.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,23 @@ async fn it_has_json() -> anyhow::Result<()> {
112112
Ok(())
113113
}
114114

115+
#[cfg(feature = "uuid")]
116+
#[sqlx_macros::test]
117+
async fn it_has_uuid() -> anyhow::Result<()> {
118+
use sqlx_oldapi::types::Uuid;
119+
#[cfg(feature = "sqlite")]
120+
let sql = "CAST('123e4567-e89b-12d3-a456-426614174000' AS TEXT)";
121+
#[cfg(feature = "mssql")]
122+
let sql = "CONVERT(uniqueidentifier, '123e4567-e89b-12d3-a456-426614174000')";
123+
#[cfg(feature = "postgres")]
124+
let sql = "CAST('123e4567-e89b-12d3-a456-426614174000' AS UUID)";
125+
assert_eq!(
126+
Uuid::parse_str("123e4567-e89b-12d3-a456-426614174000")?,
127+
get_val::<Uuid>(sql).await?
128+
);
129+
Ok(())
130+
}
131+
115132
#[sqlx_macros::test]
116133
async fn it_pings() -> anyhow::Result<()> {
117134
let mut conn = new::<Any>().await?;

0 commit comments

Comments
 (0)