sqlx_core_guts/any/
row.rs

1use crate::any::{Any, AnyColumn, AnyColumnIndex};
2use crate::column::ColumnIndex;
3use crate::database::HasValueRef;
4use crate::error::Error;
5use crate::row::Row;
6
7#[cfg(feature = "postgres")]
8use crate::postgres::PgRow;
9
10#[cfg(feature = "mysql")]
11use crate::mysql::MySqlRow;
12
13#[cfg(feature = "sqlite")]
14use crate::sqlite::SqliteRow;
15
16#[cfg(feature = "mssql")]
17use crate::mssql::MssqlRow;
18
19pub struct AnyRow {
20    pub(crate) kind: AnyRowKind,
21    pub(crate) columns: Vec<AnyColumn>,
22}
23
24impl crate::row::private_row::Sealed for AnyRow {}
25
26pub(crate) enum AnyRowKind {
27    #[cfg(feature = "postgres")]
28    Postgres(PgRow),
29
30    #[cfg(feature = "mysql")]
31    MySql(MySqlRow),
32
33    #[cfg(feature = "sqlite")]
34    Sqlite(SqliteRow),
35
36    #[cfg(feature = "mssql")]
37    Mssql(MssqlRow),
38}
39
40impl Row for AnyRow {
41    type Database = Any;
42
43    fn columns(&self) -> &[AnyColumn] {
44        &self.columns
45    }
46
47    fn try_get_raw<I>(
48        &self,
49        index: I,
50    ) -> Result<<Self::Database as HasValueRef<'_>>::ValueRef, Error>
51    where
52        I: ColumnIndex<Self>,
53    {
54        let index = index.index(self)?;
55
56        match &self.kind {
57            #[cfg(feature = "postgres")]
58            AnyRowKind::Postgres(row) => row.try_get_raw(index).map(Into::into),
59
60            #[cfg(feature = "mysql")]
61            AnyRowKind::MySql(row) => row.try_get_raw(index).map(Into::into),
62
63            #[cfg(feature = "sqlite")]
64            AnyRowKind::Sqlite(row) => row.try_get_raw(index).map(Into::into),
65
66            #[cfg(feature = "mssql")]
67            AnyRowKind::Mssql(row) => row.try_get_raw(index).map(Into::into),
68        }
69    }
70}
71
72impl<'i> ColumnIndex<AnyRow> for &'i str
73where
74    &'i str: AnyColumnIndex,
75{
76    fn index(&self, row: &AnyRow) -> Result<usize, Error> {
77        match &row.kind {
78            #[cfg(feature = "postgres")]
79            AnyRowKind::Postgres(row) => self.index(row),
80
81            #[cfg(feature = "mysql")]
82            AnyRowKind::MySql(row) => self.index(row),
83
84            #[cfg(feature = "sqlite")]
85            AnyRowKind::Sqlite(row) => self.index(row),
86
87            #[cfg(feature = "mssql")]
88            AnyRowKind::Mssql(row) => self.index(row),
89        }
90    }
91}