sqlx_core_oldapi/mysql/
row.rs1use crate::column::ColumnIndex;
2use crate::error::Error;
3use crate::ext::ustr::UStr;
4use crate::mysql::{protocol, MySql, MySqlColumn, MySqlValueFormat, MySqlValueRef};
5use crate::row::Row;
6use crate::HashMap;
7use std::sync::Arc;
8
9#[derive(Debug)]
11pub struct MySqlRow {
12 pub(crate) row: protocol::Row,
13 pub(crate) format: MySqlValueFormat,
14 pub(crate) columns: Arc<Vec<MySqlColumn>>,
15 pub(crate) column_names: Arc<HashMap<UStr, usize>>,
16}
17
18impl crate::row::private_row::Sealed for MySqlRow {}
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 .map(|v| *v)
50 }
51}
52
53#[cfg(feature = "any")]
54impl From<MySqlRow> for crate::any::AnyRow {
55 #[inline]
56 fn from(row: MySqlRow) -> Self {
57 crate::any::AnyRow {
58 columns: row.columns.iter().map(|col| col.clone().into()).collect(),
59
60 kind: crate::any::row::AnyRowKind::MySql(row),
61 }
62 }
63}