mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-11-06 00:12:44 +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,
|
T: 'r + DeserializeOwned,
|
||||||
{
|
{
|
||||||
fn accepts(ty: &MySqlTypeInfo) -> bool {
|
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> {
|
fn decode(value: MySqlValueRef<'r>) -> Result<Self, BoxDynError> {
|
||||||
|
|||||||
@ -2,7 +2,6 @@ use futures::TryStreamExt;
|
|||||||
use sqlx::mysql::{MySql, MySqlPool, MySqlRow};
|
use sqlx::mysql::{MySql, MySqlPool, MySqlRow};
|
||||||
use sqlx::{Connection, Executor, Row};
|
use sqlx::{Connection, Executor, Row};
|
||||||
use sqlx_test::new;
|
use sqlx_test::new;
|
||||||
use std::env;
|
|
||||||
|
|
||||||
#[sqlx_macros::test]
|
#[sqlx_macros::test]
|
||||||
async fn it_connects() -> anyhow::Result<()> {
|
async fn it_connects() -> anyhow::Result<()> {
|
||||||
|
|||||||
@ -123,11 +123,11 @@ mod json_tests {
|
|||||||
|
|
||||||
test_type!(json<JsonValue>(
|
test_type!(json<JsonValue>(
|
||||||
MySql,
|
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"),
|
"'\"Hello, World\"'" == json!("Hello, World"),
|
||||||
"'\"😎\"'" == json!("😎"),
|
"'\"😎\"'" == json!("😎"),
|
||||||
"'\"🙋♀️\"'" == json!("🙋♀️"),
|
"'\"🙋♀️\"'" == json!("🙋♀️"),
|
||||||
"'[\"Hello\", \"World!\"]'" == json!(["Hello", "World!"])
|
"'[\"Hello\",\"World!\"]'" == json!(["Hello", "World!"])
|
||||||
));
|
));
|
||||||
|
|
||||||
#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq)]
|
#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq)]
|
||||||
@ -138,7 +138,7 @@ mod json_tests {
|
|||||||
|
|
||||||
test_type!(json_struct<Json<Friend>>(
|
test_type!(json_struct<Json<Friend>>(
|
||||||
MySql,
|
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",
|
||||||
"\'{\"name\": \"Joe\", \"age\":33}\'" == Json(Friend { name: "Joe".to_string(), age: 33 })
|
"\'{\"name\":\"Joe\",\"age\":33}\'" == Json(Friend { name: "Joe".to_string(), age: 33 })
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user