fix(mysql): display TINYINT(1) as integer instead of boolean (#120)
MySQL BOOLEAN is an alias for TINYINT(1). The sqlx driver reports it as BOOLEAN type, causing values to display as true/false. Read the value as i8 first to show the actual integer value.
This commit is contained in:
parent
ecdc86a478
commit
310468b44e
|
|
@ -94,7 +94,12 @@ fn mysql_value_to_json(row: &MySqlRow, idx: usize, type_name: &str) -> serde_jso
|
|||
}
|
||||
|
||||
if upper_type == "BOOLEAN" {
|
||||
return row.try_get::<bool, _>(idx).map(serde_json::Value::Bool).unwrap_or(serde_json::Value::Null);
|
||||
// MySQL BOOLEAN is an alias for TINYINT(1); display as integer
|
||||
return row
|
||||
.try_get::<i8, _>(idx)
|
||||
.map(|v| serde_json::Value::Number((v as i64).into()))
|
||||
.or_else(|_| row.try_get::<bool, _>(idx).map(|v| serde_json::Value::Number((v as i64).into())))
|
||||
.unwrap_or(serde_json::Value::Null);
|
||||
}
|
||||
|
||||
if upper_type.contains("BIGINT") {
|
||||
|
|
|
|||
Loading…
Reference in New Issue