Closed guchengxi1994 closed 2 years ago
Hi. Please use the Row
type as a target type for a mysql row.
Example:
let query = "SELECT 1 as the_first_column, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20";
let row: mysql::Row = query.first(&mut conn)?.unwrap();
// take the first column value by the column name
let the_fist_column: u8 = row.take("the_fist_column").unwrap();
// take the last column value by the column index
let the_last_column: u8 = row.take(19).unwrap();
assert_eq!(the_fist_column, 1);
assert_eq!(the_last_column, 20);
Another option is to use frunk::Hlist
type as a target type and then to use into_tuple2
to get columns values.
I was using this tool in this situation, but it raise this exception.