mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-11-01 14:02:46 +00:00
fix(mysql): tweak JSON type so it accepts BINARY in addition to CHAR (and make tests pass in MySQL 5.5)
This commit is contained in:
parent
6fcb520ac9
commit
a2c55b9f31
@ -34,7 +34,9 @@ where
|
||||
T: 'r + DeserializeOwned,
|
||||
{
|
||||
fn accepts(ty: &MySqlTypeInfo) -> bool {
|
||||
ty.r#type == ColumnType::Json || <&str as Decode<MySql>>::accepts(ty)
|
||||
ty.r#type == ColumnType::Json
|
||||
|| <&str as Decode<MySql>>::accepts(ty)
|
||||
|| <&[u8] as Decode<MySql>>::accepts(ty)
|
||||
}
|
||||
|
||||
fn decode(value: MySqlValueRef<'r>) -> Result<Self, BoxDynError> {
|
||||
|
||||
@ -2,7 +2,6 @@ use futures::TryStreamExt;
|
||||
use sqlx::mysql::{MySql, MySqlPool, MySqlRow};
|
||||
use sqlx::{Connection, Executor, Row};
|
||||
use sqlx_test::new;
|
||||
use std::env;
|
||||
|
||||
#[sqlx_macros::test]
|
||||
async fn it_connects() -> anyhow::Result<()> {
|
||||
|
||||
@ -123,11 +123,11 @@ mod json_tests {
|
||||
|
||||
test_type!(json<JsonValue>(
|
||||
MySql,
|
||||
"SELECT CAST({0} AS JSON) <=> CAST(? AS JSON), CAST({0} AS JSON) as _2, ? as _3",
|
||||
"SELECT CAST({0} AS BINARY) <=> CAST(? AS BINARY), CAST({0} AS BINARY) as _2, ? as _3",
|
||||
"'\"Hello, World\"'" == json!("Hello, World"),
|
||||
"'\"😎\"'" == json!("😎"),
|
||||
"'\"🙋♀️\"'" == json!("🙋♀️"),
|
||||
"'[\"Hello\", \"World!\"]'" == json!(["Hello", "World!"])
|
||||
"'[\"Hello\",\"World!\"]'" == json!(["Hello", "World!"])
|
||||
));
|
||||
|
||||
#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq)]
|
||||
@ -138,7 +138,7 @@ mod json_tests {
|
||||
|
||||
test_type!(json_struct<Json<Friend>>(
|
||||
MySql,
|
||||
"SELECT CAST({0} AS JSON) <=> CAST(? AS JSON), CAST({0} AS JSON) as _2, ? as _3",
|
||||
"\'{\"name\": \"Joe\", \"age\":33}\'" == Json(Friend { name: "Joe".to_string(), age: 33 })
|
||||
"SELECT CAST({0} AS BINARY) <=> CAST(? AS BINARY), CAST({0} AS BINARY) as _2, ? as _3",
|
||||
"\'{\"name\":\"Joe\",\"age\":33}\'" == Json(Friend { name: "Joe".to_string(), age: 33 })
|
||||
));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user