sqlx_core_oldapi/any/
arguments.rs1use crate::any::Any;
2use crate::arguments::Arguments;
3use crate::encode::Encode;
4use crate::types::Type;
5
6#[derive(Default)]
7pub struct AnyArguments<'q> {
8 values: Vec<Box<dyn Encode<'q, Any> + Send + 'q>>,
9}
10
11impl<'q> Arguments<'q> for AnyArguments<'q> {
12 type Database = Any;
13
14 fn reserve(&mut self, additional: usize, _size: usize) {
15 self.values.reserve(additional);
16 }
17
18 fn add<T>(&mut self, value: T)
19 where
20 T: 'q + Send + Encode<'q, Self::Database> + Type<Self::Database>,
21 {
22 self.values.push(Box::new(value));
23 }
24}
25
26pub struct AnyArgumentBuffer<'q>(pub(crate) AnyArgumentBufferKind<'q>);
27
28pub(crate) enum AnyArgumentBufferKind<'q> {
29 #[cfg(feature = "postgres")]
30 Postgres(
31 crate::postgres::PgArguments,
32 std::marker::PhantomData<&'q ()>,
33 ),
34
35 #[cfg(feature = "mysql")]
36 MySql(
37 crate::mysql::MySqlArguments,
38 std::marker::PhantomData<&'q ()>,
39 ),
40
41 #[cfg(feature = "sqlite")]
42 Sqlite(crate::sqlite::SqliteArguments<'q>),
43
44 #[cfg(feature = "mssql")]
45 Mssql(
46 crate::mssql::MssqlArguments,
47 std::marker::PhantomData<&'q ()>,
48 ),
49
50 #[cfg(feature = "odbc")]
51 Odbc(crate::odbc::OdbcArguments, std::marker::PhantomData<&'q ()>),
52}
53
54#[cfg(feature = "sqlite")]
58#[allow(irrefutable_let_patterns)]
59impl<'q> From<AnyArguments<'q>> for crate::sqlite::SqliteArguments<'q> {
60 fn from(args: AnyArguments<'q>) -> Self {
61 let mut buf = AnyArgumentBuffer(AnyArgumentBufferKind::Sqlite(Default::default()));
62
63 for value in args.values {
64 let _ = value.encode_by_ref(&mut buf);
65 }
66
67 if let AnyArgumentBufferKind::Sqlite(args) = buf.0 {
68 args
69 } else {
70 unreachable!()
71 }
72 }
73}
74
75#[cfg(feature = "mysql")]
76#[allow(irrefutable_let_patterns)]
77impl<'q> From<AnyArguments<'q>> for crate::mysql::MySqlArguments {
78 fn from(args: AnyArguments<'q>) -> Self {
79 let mut buf = AnyArgumentBuffer(AnyArgumentBufferKind::MySql(
80 Default::default(),
81 std::marker::PhantomData,
82 ));
83
84 for value in args.values {
85 let _ = value.encode_by_ref(&mut buf);
86 }
87
88 if let AnyArgumentBufferKind::MySql(args, _) = buf.0 {
89 args
90 } else {
91 unreachable!()
92 }
93 }
94}
95
96#[cfg(feature = "mssql")]
97#[allow(irrefutable_let_patterns)]
98impl<'q> From<AnyArguments<'q>> for crate::mssql::MssqlArguments {
99 fn from(args: AnyArguments<'q>) -> Self {
100 let mut buf = AnyArgumentBuffer(AnyArgumentBufferKind::Mssql(
101 Default::default(),
102 std::marker::PhantomData,
103 ));
104
105 for value in args.values {
106 let _ = value.encode_by_ref(&mut buf);
107 }
108
109 if let AnyArgumentBufferKind::Mssql(args, _) = buf.0 {
110 args
111 } else {
112 unreachable!()
113 }
114 }
115}
116
117#[cfg(feature = "postgres")]
118#[allow(irrefutable_let_patterns)]
119impl<'q> From<AnyArguments<'q>> for crate::postgres::PgArguments {
120 fn from(args: AnyArguments<'q>) -> Self {
121 let mut buf = AnyArgumentBuffer(AnyArgumentBufferKind::Postgres(
122 Default::default(),
123 std::marker::PhantomData,
124 ));
125
126 for value in args.values {
127 let _ = value.encode_by_ref(&mut buf);
128 }
129
130 if let AnyArgumentBufferKind::Postgres(args, _) = buf.0 {
131 args
132 } else {
133 unreachable!()
134 }
135 }
136}
137
138#[cfg(feature = "odbc")]
139#[allow(irrefutable_let_patterns)]
140impl<'q> From<AnyArguments<'q>> for crate::odbc::OdbcArguments {
141 fn from(args: AnyArguments<'q>) -> Self {
142 let mut buf = AnyArgumentBuffer(AnyArgumentBufferKind::Odbc(
143 Default::default(),
144 std::marker::PhantomData,
145 ));
146
147 for value in args.values {
148 let _ = value.encode_by_ref(&mut buf);
149 }
150
151 if let AnyArgumentBufferKind::Odbc(args, _) = buf.0 {
152 args
153 } else {
154 unreachable!()
155 }
156 }
157}