@@ -53,13 +53,16 @@ fn decode_raw<'a, T: Decode<'a, sqlx::any::Any> + Default>(
53
53
}
54
54
55
55
pub fn sql_nonnull_to_json < ' r > ( mut get_ref : impl FnMut ( ) -> sqlx:: any:: AnyValueRef < ' r > ) -> Value {
56
+ use AnyTypeInfoKind :: { Mssql , MySql } ;
56
57
let raw_value = get_ref ( ) ;
57
58
let type_info = raw_value. type_info ( ) ;
58
59
let type_name = type_info. name ( ) ;
59
60
log:: trace!( "Decoding a value of type {type_name:?} (type info: {type_info:?})" ) ;
61
+ let AnyTypeInfo ( ref db_type) = * type_info;
60
62
match type_name {
61
- "REAL" | "FLOAT" | "FLOAT4" | "FLOAT8" | "DOUBLE" | "NUMERIC" | "DECIMAL" | "MONEY"
62
- | "SMALLMONEY" => decode_raw :: < f64 > ( raw_value) . into ( ) ,
63
+ "REAL" | "FLOAT" | "FLOAT4" | "FLOAT8" | "DOUBLE" | "NUMERIC" | "DECIMAL" => {
64
+ decode_raw :: < f64 > ( raw_value) . into ( )
65
+ }
63
66
"INT8" | "BIGINT" | "SERIAL8" | "BIGSERIAL" | "IDENTITY" | "INT64" | "INTEGER8"
64
67
| "BIGINT SIGNED" => decode_raw :: < i64 > ( raw_value) . into ( ) ,
65
68
"INT" | "INT4" | "INTEGER" | "MEDIUMINT" | "YEAR" => decode_raw :: < i32 > ( raw_value) . into ( ) ,
@@ -69,15 +72,11 @@ pub fn sql_nonnull_to_json<'r>(mut get_ref: impl FnMut() -> sqlx::any::AnyValueR
69
72
decode_raw :: < u32 > ( raw_value) . into ( )
70
73
}
71
74
"BOOL" | "BOOLEAN" => decode_raw :: < bool > ( raw_value) . into ( ) ,
72
- "BIT" if matches ! ( * type_info, AnyTypeInfo ( AnyTypeInfoKind :: Mssql ( _) ) ) => {
73
- decode_raw :: < bool > ( raw_value) . into ( )
74
- }
75
- "BIT" if matches ! ( * type_info, AnyTypeInfo ( AnyTypeInfoKind :: MySql ( ref mysql_type) ) if mysql_type. max_size( ) == Some ( 1 ) ) => {
75
+ "BIT" if matches ! ( db_type, Mssql ( _) ) => decode_raw :: < bool > ( raw_value) . into ( ) ,
76
+ "BIT" if matches ! ( db_type, MySql ( mysql_type) if mysql_type. max_size( ) == Some ( 1 ) ) => {
76
77
decode_raw :: < bool > ( raw_value) . into ( )
77
78
}
78
- "BIT" if matches ! ( * type_info, AnyTypeInfo ( AnyTypeInfoKind :: MySql ( _) ) ) => {
79
- decode_raw :: < u64 > ( raw_value) . into ( )
80
- }
79
+ "BIT" if matches ! ( db_type, MySql ( _) ) => decode_raw :: < u64 > ( raw_value) . into ( ) ,
81
80
"DATE" => decode_raw :: < chrono:: NaiveDate > ( raw_value)
82
81
. to_string ( )
83
82
. into ( ) ,
@@ -93,6 +92,9 @@ pub fn sql_nonnull_to_json<'r>(mut get_ref: impl FnMut() -> sqlx::any::AnyValueR
93
92
. format ( "%FT%T%.f" )
94
93
. to_string ( )
95
94
. into ( ) ,
95
+ "MONEY" | "SMALLMONEY" if matches ! ( db_type, Mssql ( _) ) => {
96
+ decode_raw :: < f64 > ( raw_value) . into ( )
97
+ }
96
98
"JSON" | "JSON[]" | "JSONB" | "JSONB[]" => decode_raw :: < Value > ( raw_value) ,
97
99
// Deserialize as a string by default
98
100
_ => decode_raw :: < String > ( raw_value) . into ( ) ,
@@ -212,7 +214,7 @@ mod tests {
212
214
"jsonb" : { "key" : "value" } ,
213
215
"age_interval" : "2 mons 13 days" ,
214
216
"justified_interval" : "1 year 2 mons 3 days" ,
215
- "money_val" : 0.0 // TODO: fix this. This should be 1234.56
217
+ "money_val" : "$1,234.56"
216
218
} ) ,
217
219
) ;
218
220
Ok ( ( ) )
0 commit comments