mysql_connector/model/
from_query_result.rs1use crate::{connection::types::Column, error::ParseError, types::Value};
2
3pub trait FromQueryResultMapping<ModelData: super::ModelData>: Default {
4 fn set_mapping_inner(&mut self, column: &Column, table: &str, index: usize);
5
6 fn set_mapping(&mut self, column: &Column, table: &str, index: usize) {
7 self.set_mapping_inner(
8 column,
9 table
10 .strip_prefix(ModelData::TABLE_WITH_POINT)
11 .unwrap_or(table),
12 index,
13 )
14 }
15
16 fn from_columns(columns: &[Column]) -> Self {
17 let mut this = Self::default();
18 for (i, column) in columns.iter().enumerate() {
19 this.set_mapping(column, column.table(), i);
20 }
21 this
22 }
23}
24
25pub trait FromQueryResult: super::ModelData + Sized {
26 type Mapping: FromQueryResultMapping<Self>;
27
28 fn from_mapping_and_row(
29 mapping: &Self::Mapping,
30 row: &mut Vec<Value>,
31 ) -> std::result::Result<Self, ParseError>;
32}