sea_query_sqlx/
sqlx_postgres.rs1#[cfg(feature = "with-bigdecimal")]
2use bigdecimal::BigDecimal;
3#[cfg(feature = "with-chrono")]
4use chrono::{DateTime, FixedOffset, Local, NaiveDate, NaiveDateTime, NaiveTime, Utc};
5#[cfg(feature = "with-ipnetwork")]
6use ipnetwork::IpNetwork;
7#[cfg(feature = "with-mac_address")]
8use mac_address::MacAddress;
9#[cfg(feature = "with-rust_decimal")]
10use rust_decimal::Decimal;
11#[cfg(feature = "with-json")]
12use serde_json::Value as Json;
13#[cfg(feature = "with-uuid")]
14use uuid::Uuid;
15
16use sea_query::{ArrayType, Value};
17
18use crate::SqlxValues;
19
20impl sqlx::IntoArguments<'_, sqlx::postgres::Postgres> for SqlxValues {
21 fn into_arguments(self) -> sqlx::postgres::PgArguments {
22 let mut args = sqlx::postgres::PgArguments::default();
23 for arg in self.0.into_iter() {
24 use sqlx::Arguments;
25 match arg {
26 Value::Bool(b) => {
27 let _ = args.add(b);
28 }
29 Value::TinyInt(i) => {
30 let _ = args.add(i);
31 }
32 Value::SmallInt(i) => {
33 let _ = args.add(i);
34 }
35 Value::Int(i) => {
36 let _ = args.add(i);
37 }
38 Value::BigInt(i) => {
39 let _ = args.add(i);
40 }
41 Value::TinyUnsigned(i) => {
42 let _ = args.add(i.map(|i| i as i16));
43 }
44 Value::SmallUnsigned(i) => {
45 let _ = args.add(i.map(|i| i as i32));
46 }
47 Value::Unsigned(i) => {
48 let _ = args.add(i.map(|i| i as i64));
49 }
50 Value::BigUnsigned(i) => {
51 let _ = args.add(i.map(|i| <i64 as TryFrom<u64>>::try_from(i).unwrap()));
52 }
53 Value::Float(f) => {
54 let _ = args.add(f);
55 }
56 Value::Double(d) => {
57 let _ = args.add(d);
58 }
59 Value::String(s) => {
60 let _ = args.add(s.as_deref());
61 }
62 Value::Char(c) => {
63 let _ = args.add(c.map(|c| c.to_string()));
64 }
65 Value::Bytes(b) => {
66 let _ = args.add(b.as_deref());
67 }
68 #[cfg(feature = "with-chrono")]
69 Value::ChronoDate(d) => {
70 let _ = args.add(d);
71 }
72 #[cfg(feature = "with-chrono")]
73 Value::ChronoTime(t) => {
74 let _ = args.add(t);
75 }
76 #[cfg(feature = "with-chrono")]
77 Value::ChronoDateTime(t) => {
78 let _ = args.add(t);
79 }
80 #[cfg(feature = "with-chrono")]
81 Value::ChronoDateTimeUtc(t) => {
82 let _ = args.add(t);
83 }
84 #[cfg(feature = "with-chrono")]
85 Value::ChronoDateTimeLocal(t) => {
86 let _ = args.add(t);
87 }
88 #[cfg(feature = "with-chrono")]
89 Value::ChronoDateTimeWithTimeZone(t) => {
90 let _ = args.add(t);
91 }
92 #[cfg(feature = "with-time")]
93 Value::TimeDate(t) => {
94 let _ = args.add(t);
95 }
96 #[cfg(feature = "with-time")]
97 Value::TimeTime(t) => {
98 let _ = args.add(t);
99 }
100 #[cfg(feature = "with-time")]
101 Value::TimeDateTime(t) => {
102 let _ = args.add(t);
103 }
104 #[cfg(feature = "with-time")]
105 Value::TimeDateTimeWithTimeZone(t) => {
106 let _ = args.add(t);
107 }
108 #[cfg(feature = "with-uuid")]
109 Value::Uuid(uuid) => {
110 let _ = args.add(uuid);
111 }
112 #[cfg(feature = "with-rust_decimal")]
113 Value::Decimal(d) => {
114 let _ = args.add(d);
115 }
116 #[cfg(feature = "with-bigdecimal")]
117 Value::BigDecimal(d) => {
118 let _ = args.add(d.as_deref());
119 }
120 #[cfg(feature = "with-json")]
121 Value::Json(j) => {
122 let _ = args.add(j.as_deref());
123 }
124 #[cfg(feature = "with-ipnetwork")]
125 Value::IpNetwork(ip) => {
126 let _ = args.add(ip);
127 }
128 #[cfg(feature = "with-mac_address")]
129 Value::MacAddress(mac) => {
130 let _ = args.add(mac);
131 }
132 #[cfg(feature = "postgres-array")]
133 Value::Array(ty, v) => match ty {
134 ArrayType::Bool => {
135 let value: Option<Vec<bool>> = Value::Array(ty, v)
136 .expect("This Value::Array should consist of Value::Bool");
137 let _ = args.add(value);
138 }
139 ArrayType::TinyInt => {
140 let value: Option<Vec<i8>> = Value::Array(ty, v)
141 .expect("This Value::Array should consist of Value::TinyInt");
142 let _ = args.add(value);
143 }
144 ArrayType::SmallInt => {
145 let value: Option<Vec<i16>> = Value::Array(ty, v)
146 .expect("This Value::Array should consist of Value::SmallInt");
147 let _ = args.add(value);
148 }
149 ArrayType::Int => {
150 let value: Option<Vec<i32>> = Value::Array(ty, v)
151 .expect("This Value::Array should consist of Value::Int");
152 let _ = args.add(value);
153 }
154 ArrayType::BigInt => {
155 let value: Option<Vec<i64>> = Value::Array(ty, v)
156 .expect("This Value::Array should consist of Value::BigInt");
157 let _ = args.add(value);
158 }
159 ArrayType::TinyUnsigned => {
160 let value: Option<Vec<u8>> = Value::Array(ty, v)
161 .expect("This Value::Array should consist of Value::TinyUnsigned");
162 let value: Option<Vec<i16>> =
163 value.map(|vec| vec.into_iter().map(|i| i as i16).collect());
164 let _ = args.add(value);
165 }
166 ArrayType::SmallUnsigned => {
167 let value: Option<Vec<u16>> = Value::Array(ty, v)
168 .expect("This Value::Array should consist of Value::SmallUnsigned");
169 let value: Option<Vec<i32>> =
170 value.map(|vec| vec.into_iter().map(|i| i as i32).collect());
171 let _ = args.add(value);
172 }
173 ArrayType::Unsigned => {
174 let value: Option<Vec<u32>> = Value::Array(ty, v)
175 .expect("This Value::Array should consist of Value::Unsigned");
176 let value: Option<Vec<i64>> =
177 value.map(|vec| vec.into_iter().map(|i| i as i64).collect());
178 let _ = args.add(value);
179 }
180 ArrayType::BigUnsigned => {
181 let value: Option<Vec<u64>> = Value::Array(ty, v)
182 .expect("This Value::Array should consist of Value::BigUnsigned");
183 let value: Option<Vec<i64>> = value.map(|vec| {
184 vec.into_iter()
185 .map(|i| <i64 as TryFrom<u64>>::try_from(i).unwrap())
186 .collect()
187 });
188 let _ = args.add(value);
189 }
190 ArrayType::Float => {
191 let value: Option<Vec<f32>> = Value::Array(ty, v)
192 .expect("This Value::Array should consist of Value::Float");
193 let _ = args.add(value);
194 }
195 ArrayType::Double => {
196 let value: Option<Vec<f64>> = Value::Array(ty, v)
197 .expect("This Value::Array should consist of Value::Double");
198 let _ = args.add(value);
199 }
200 ArrayType::String => {
201 let value: Option<Vec<String>> = Value::Array(ty, v)
202 .expect("This Value::Array should consist of Value::String");
203 let _ = args.add(value);
204 }
205 ArrayType::Char => {
206 let value: Option<Vec<char>> = Value::Array(ty, v)
207 .expect("This Value::Array should consist of Value::Char");
208 let value: Option<Vec<String>> =
209 value.map(|vec| vec.into_iter().map(|c| c.to_string()).collect());
210 let _ = args.add(value);
211 }
212 ArrayType::Bytes => {
213 let value: Option<Vec<Vec<u8>>> = Value::Array(ty, v)
214 .expect("This Value::Array should consist of Value::Bytes");
215 let _ = args.add(value);
216 }
217 #[cfg(feature = "with-chrono")]
218 ArrayType::ChronoDate => {
219 let value: Option<Vec<NaiveDate>> = Value::Array(ty, v)
220 .expect("This Value::Array should consist of Value::ChronoDate");
221 let _ = args.add(value);
222 }
223 #[cfg(feature = "with-chrono")]
224 ArrayType::ChronoTime => {
225 let value: Option<Vec<NaiveTime>> = Value::Array(ty, v)
226 .expect("This Value::Array should consist of Value::ChronoTime");
227 let _ = args.add(value);
228 }
229 #[cfg(feature = "with-chrono")]
230 ArrayType::ChronoDateTime => {
231 let value: Option<Vec<NaiveDateTime>> = Value::Array(ty, v)
232 .expect("This Value::Array should consist of Value::ChronoDateTime");
233 let _ = args.add(value);
234 }
235 #[cfg(feature = "with-chrono")]
236 ArrayType::ChronoDateTimeUtc => {
237 let value: Option<Vec<DateTime<Utc>>> = Value::Array(ty, v)
238 .expect("This Value::Array should consist of Value::ChronoDateTimeUtc");
239 let _ = args.add(value);
240 }
241 #[cfg(feature = "with-chrono")]
242 ArrayType::ChronoDateTimeLocal => {
243 let value: Option<Vec<DateTime<Local>>> = Value::Array(ty, v).expect(
244 "This Value::Array should consist of Value::ChronoDateTimeLocal",
245 );
246 let _ = args.add(value);
247 }
248 #[cfg(feature = "with-chrono")]
249 ArrayType::ChronoDateTimeWithTimeZone => {
250 let value: Option<Vec<DateTime<FixedOffset>>> = Value::Array(ty, v).expect(
251 "This Value::Array should consist of Value::ChronoDateTimeWithTimeZone",
252 );
253 let _ = args.add(value);
254 }
255 #[cfg(feature = "with-time")]
256 ArrayType::TimeDate => {
257 let value: Option<Vec<time::Date>> = Value::Array(ty, v)
258 .expect("This Value::Array should consist of Value::TimeDate");
259 let _ = args.add(value);
260 }
261 #[cfg(feature = "with-time")]
262 ArrayType::TimeTime => {
263 let value: Option<Vec<time::Time>> = Value::Array(ty, v)
264 .expect("This Value::Array should consist of Value::TimeTime");
265 let _ = args.add(value);
266 }
267 #[cfg(feature = "with-time")]
268 ArrayType::TimeDateTime => {
269 let value: Option<Vec<time::PrimitiveDateTime>> = Value::Array(ty, v)
270 .expect("This Value::Array should consist of Value::TimeDateTime");
271 let _ = args.add(value);
272 }
273 #[cfg(feature = "with-time")]
274 ArrayType::TimeDateTimeWithTimeZone => {
275 let value: Option<Vec<time::OffsetDateTime>> = Value::Array(ty, v).expect(
276 "This Value::Array should consist of Value::TimeDateTimeWithTimeZone",
277 );
278 let _ = args.add(value);
279 }
280 #[cfg(feature = "with-uuid")]
281 ArrayType::Uuid => {
282 let value: Option<Vec<Uuid>> = Value::Array(ty, v)
283 .expect("This Value::Array should consist of Value::Uuid");
284 let _ = args.add(value);
285 }
286 #[cfg(feature = "with-rust_decimal")]
287 ArrayType::Decimal => {
288 let value: Option<Vec<Decimal>> = Value::Array(ty, v)
289 .expect("This Value::Array should consist of Value::Decimal");
290 let _ = args.add(value);
291 }
292 #[cfg(feature = "with-bigdecimal")]
293 ArrayType::BigDecimal => {
294 let value: Option<Vec<BigDecimal>> = Value::Array(ty, v)
295 .expect("This Value::Array should consist of Value::BigDecimal");
296 let _ = args.add(value);
297 }
298 #[cfg(feature = "with-json")]
299 ArrayType::Json => {
300 let value: Option<Vec<Json>> = Value::Array(ty, v)
301 .expect("This Value::Array should consist of Value::Json");
302 let _ = args.add(value);
303 }
304 #[cfg(feature = "with-ipnetwork")]
305 ArrayType::IpNetwork => {
306 let value: Option<Vec<IpNetwork>> = Value::Array(ty, v)
307 .expect("This Value::Array should consist of Value::IpNetwork");
308 let _ = args.add(value);
309 }
310 #[cfg(feature = "with-mac_address")]
311 ArrayType::MacAddress => {
312 let value: Option<Vec<MacAddress>> = Value::Array(ty, v)
313 .expect("This Value::Array should consist of Value::MacAddress");
314 let _ = args.add(value);
315 }
316 },
317 #[cfg(feature = "postgres-vector")]
318 Value::Vector(v) => {
319 let _ = args.add(v);
320 } }
325 }
326 args
327 }
328}