sqlx_core_oldapi/any/
column.rs1use crate::any::{Any, AnyTypeInfo};
2use crate::column::{Column, ColumnIndex};
3
4#[cfg(feature = "postgres")]
5use crate::postgres::{PgColumn, PgRow, PgStatement};
6
7#[cfg(feature = "mysql")]
8use crate::mysql::{MySqlColumn, MySqlRow, MySqlStatement};
9
10#[cfg(feature = "sqlite")]
11use crate::sqlite::{SqliteColumn, SqliteRow, SqliteStatement};
12
13#[cfg(feature = "mssql")]
14use crate::mssql::{MssqlColumn, MssqlRow, MssqlStatement};
15
16#[cfg(feature = "odbc")]
17use crate::odbc::{OdbcColumn, OdbcRow, OdbcStatement};
18
19#[derive(Debug, Clone)]
20pub struct AnyColumn {
21 pub(crate) kind: AnyColumnKind,
22 pub(crate) type_info: AnyTypeInfo,
23}
24
25impl crate::column::private_column::Sealed for AnyColumn {}
26
27#[derive(Debug, Clone)]
28pub(crate) enum AnyColumnKind {
29 #[cfg(feature = "postgres")]
30 Postgres(PgColumn),
31
32 #[cfg(feature = "mysql")]
33 MySql(MySqlColumn),
34
35 #[cfg(feature = "sqlite")]
36 Sqlite(SqliteColumn),
37
38 #[cfg(feature = "mssql")]
39 Mssql(MssqlColumn),
40
41 #[cfg(feature = "odbc")]
42 Odbc(OdbcColumn),
43}
44
45impl Column for AnyColumn {
46 type Database = Any;
47
48 fn ordinal(&self) -> usize {
49 match &self.kind {
50 #[cfg(feature = "postgres")]
51 AnyColumnKind::Postgres(row) => row.ordinal(),
52
53 #[cfg(feature = "mysql")]
54 AnyColumnKind::MySql(row) => row.ordinal(),
55
56 #[cfg(feature = "sqlite")]
57 AnyColumnKind::Sqlite(row) => row.ordinal(),
58
59 #[cfg(feature = "mssql")]
60 AnyColumnKind::Mssql(row) => row.ordinal(),
61
62 #[cfg(feature = "odbc")]
63 AnyColumnKind::Odbc(row) => row.ordinal(),
64 }
65 }
66
67 fn name(&self) -> &str {
68 match &self.kind {
69 #[cfg(feature = "postgres")]
70 AnyColumnKind::Postgres(row) => row.name(),
71
72 #[cfg(feature = "mysql")]
73 AnyColumnKind::MySql(row) => row.name(),
74
75 #[cfg(feature = "sqlite")]
76 AnyColumnKind::Sqlite(row) => row.name(),
77
78 #[cfg(feature = "mssql")]
79 AnyColumnKind::Mssql(row) => row.name(),
80
81 #[cfg(feature = "odbc")]
82 AnyColumnKind::Odbc(row) => row.name(),
83 }
84 }
85
86 fn type_info(&self) -> &AnyTypeInfo {
87 &self.type_info
88 }
89}
90
91macro_rules! impl_any_column_index_for_databases {
93 ($(($row:ident, $stmt:ident)),+) => {
94 pub trait AnyColumnIndex: $(ColumnIndex<$row> + for<'q> ColumnIndex<$stmt<'q>> +)+ Sized {}
95
96 impl<I: ?Sized> AnyColumnIndex for I
97 where
98 I: $(ColumnIndex<$row> + for<'q> ColumnIndex<$stmt<'q>> +)+ Sized
99 {}
100 };
101}
102
103for_all_feature_combinations! {
105 entries: [
106 ("postgres", (PgRow, PgStatement)),
107 ("mysql", (MySqlRow, MySqlStatement)),
108 ("mssql", (MssqlRow, MssqlStatement)),
109 ("sqlite", (SqliteRow, SqliteStatement)),
110 ("odbc", (OdbcRow, OdbcStatement)),
111 ],
112 callback: impl_any_column_index_for_databases
113}