Skip to content

Commit fba6797

Browse files
authored
add support for the uuid type on the Any database (#30)
* add support for the uuid type on the Any database * Fix UUID test for MySQL The previous test used the wrong SQL for MySQL. This commit corrects it. * Fix UUID test for various databases * Fix MSSQL UUID test Fix MSSQL UUID test The MSSQL UUID test was failing due to an incorrect query string. This commit removes the extra character.
1 parent 2056e23 commit fba6797

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,24 @@ 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+
assert_eq!(
120+
Uuid::parse_str("123e4567-e89b-12d3-a456-426614174000")?,
121+
get_val::<Uuid>(if cfg!(feature = "mssql") {
122+
"CONVERT(uniqueidentifier, '123e4567-e89b-12d3-a456-426614174000')"
123+
} else if cfg!(feature = "postgres") {
124+
"'123e4567-e89b-12d3-a456-426614174000'::uuid"
125+
} else {
126+
"x'123e4567e89b12d3a456426614174000'"
127+
})
128+
.await?
129+
);
130+
Ok(())
131+
}
132+
115133
#[sqlx_macros::test]
116134
async fn it_pings() -> anyhow::Result<()> {
117135
let mut conn = new::<Any>().await?;

0 commit comments

Comments
 (0)