Skip to content

Commit fc1af2e

Browse files
committed
feat(sql): Add MySQL data types, fix TINYBLOB spelling
1 parent 1dc3612 commit fc1af2e

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"sql": minor
3+
"sql-js": minor
4+
---
5+
6+
Add support for MySQL `DECIMAL`, `SET`, `GEOMETRY`, `BINARY`, `VARBINARY` data types. Also fixes the `TINIYBLOB` => `TINYBLOB` spelling.

plugins/sql/src/decode/mysql.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,42 @@ pub(crate) fn to_json(v: MySqlValueRef) -> Result<JsonValue, Error> {
8585
JsonValue::Null
8686
}
8787
}
88+
"DECIMAL" => {
89+
if let Ok(v) = ValueRef::to_owned(&v).try_decode::<rust_decimal::Decimal>() {
90+
JsonValue::String(v.to_string())
91+
} else {
92+
JsonValue::Null
93+
}
94+
}
95+
"SET" | "GEOMETRY" | "BIT" => {
96+
if let Ok(v) = ValueRef::to_owned(&v).try_decode::<String>() {
97+
JsonValue::String(v)
98+
} else {
99+
JsonValue::Null
100+
}
101+
}
88102
"JSON" => ValueRef::to_owned(&v).try_decode().unwrap_or_default(),
89-
"TINIYBLOB" | "MEDIUMBLOB" | "BLOB" | "LONGBLOB" => {
103+
"BINARY" | "VARBINARY" => {
104+
// MySQL information_schema often returns text data as VARBINARY,
105+
// so try decoding as UTF-8 string first, then fall back to byte array
106+
if let Ok(v) = ValueRef::to_owned(&v).try_decode::<Vec<u8>>() {
107+
match String::from_utf8(v) {
108+
Ok(s) => JsonValue::String(s),
109+
Err(e) => {
110+
let bytes = e.into_bytes();
111+
JsonValue::Array(
112+
bytes
113+
.into_iter()
114+
.map(|n| JsonValue::Number(n.into()))
115+
.collect(),
116+
)
117+
}
118+
}
119+
} else {
120+
JsonValue::Null
121+
}
122+
}
123+
"TINYBLOB" | "MEDIUMBLOB" | "BLOB" | "LONGBLOB" => {
90124
if let Ok(v) = ValueRef::to_owned(&v).try_decode::<Vec<u8>>() {
91125
JsonValue::Array(v.into_iter().map(|n| JsonValue::Number(n.into())).collect())
92126
} else {

0 commit comments

Comments
 (0)