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