1use std::sync::Arc;
2
3pub(crate) use sqlx_core::row::*;
4
5use crate::column::ColumnIndex;
6use crate::error::Error;
7use crate::ext::ustr::UStr;
8use crate::HashMap;
9use crate::{protocol, MySql, MySqlColumn, MySqlValueFormat, MySqlValueRef};
10
11#[derive(Debug)]
13pub struct MySqlRow {
14 pub(crate) row: protocol::Row,
15 pub(crate) format: MySqlValueFormat,
16 pub(crate) columns: Arc<Vec<MySqlColumn>>,
17 pub(crate) column_names: Arc<HashMap<UStr, usize>>,
18}
19
20impl Row for MySqlRow {
21 type Database = MySql;
22
23 fn columns(&self) -> &[MySqlColumn] {
24 &self.columns
25 }
26
27 fn try_get_raw<I>(&self, index: I) -> Result<MySqlValueRef<'_>, Error>
28 where
29 I: ColumnIndex<Self>,
30 {
31 let index = index.index(self)?;
32 let column = &self.columns[index];
33 let value = self.row.get(index);
34
35 Ok(MySqlValueRef {
36 format: self.format,
37 row: Some(&self.row.storage),
38 type_info: column.type_info.clone(),
39 value,
40 })
41 }
42}
43
44impl ColumnIndex<MySqlRow> for &'_ str {
45 fn index(&self, row: &MySqlRow) -> Result<usize, Error> {
46 row.column_names
47 .get(*self)
48 .ok_or_else(|| Error::ColumnNotFound((*self).into()))
49 .copied()
50 }
51}