(res: &QueryResult, pre: &str)
| 5 | impl FromQueryResult for JsonValue { |
| 6 | #[allow(unused_variables, unused_mut)] |
| 7 | fn from_query_result(res: &QueryResult, pre: &str) -> Result<Self, DbErr> { |
| 8 | let mut map = Map::new(); |
| 9 | #[allow(unused_macros)] |
| 10 | macro_rules! try_get_type { |
| 11 | ( $type: ty, $col: ident ) => { |
| 12 | if let Ok(v) = res.try_get::<Option<$type>>(pre, &$col) { |
| 13 | map.insert($col.to_owned(), json!(v)); |
| 14 | continue; |
| 15 | } |
| 16 | }; |
| 17 | } |
| 18 | match &res.row { |
| 19 | #[cfg(feature = "sqlx-mysql")] |
| 20 | crate::QueryResultRow::SqlxMySql(row) => { |
| 21 | use serde_json::json; |
| 22 | use sqlx::{Column, MySql, Row, Type}; |
| 23 | for column in row.columns() { |
| 24 | let col = if !column.name().starts_with(pre) { |
| 25 | continue; |
| 26 | } else { |
| 27 | column.name().replacen(pre, "", 1) |
| 28 | }; |
| 29 | let col_type = column.type_info(); |
| 30 | macro_rules! match_mysql_type { |
| 31 | ( $type: ty ) => { |
| 32 | if <$type as Type<MySql>>::type_info().eq(col_type) { |
| 33 | try_get_type!($type, col) |
| 34 | } |
| 35 | }; |
| 36 | } |
| 37 | macro_rules! match_mysql_compatible_type { |
| 38 | ( $type: ty ) => { |
| 39 | if <$type as Type<MySql>>::compatible(col_type) { |
| 40 | try_get_type!($type, col) |
| 41 | } |
| 42 | }; |
| 43 | } |
| 44 | match_mysql_type!(bool); |
| 45 | match_mysql_type!(i8); |
| 46 | match_mysql_type!(i16); |
| 47 | match_mysql_type!(i32); |
| 48 | match_mysql_type!(i64); |
| 49 | match_mysql_type!(u8); |
| 50 | match_mysql_type!(u16); |
| 51 | match_mysql_type!(u32); |
| 52 | match_mysql_type!(u64); |
| 53 | match_mysql_type!(f32); |
| 54 | match_mysql_type!(f64); |
| 55 | match_mysql_type!(String); |
| 56 | #[cfg(feature = "with-chrono")] |
| 57 | match_mysql_type!(chrono::NaiveDate); |
| 58 | #[cfg(feature = "with-chrono")] |
| 59 | match_mysql_type!(chrono::NaiveTime); |
| 60 | #[cfg(feature = "with-chrono")] |
| 61 | match_mysql_type!(chrono::NaiveDateTime); |
| 62 | #[cfg(feature = "with-chrono")] |
| 63 | match_mysql_type!(chrono::DateTime<chrono::Utc>); |
| 64 | #[cfg(feature = "with-time")] |
nothing calls this directly
no test coverage detected