1use futures::lock::Mutex;
2use log::LevelFilter;
3use sea_query::Values;
4use std::{future::Future, pin::Pin, sync::Arc};
5
6use sqlx::{
7 pool::PoolConnection,
8 postgres::{PgConnectOptions, PgQueryResult, PgRow},
9 Connection, Executor, PgPool, Postgres,
10};
11
12use sea_query_binder::SqlxValues;
13use tracing::instrument;
14
15use crate::{
16 debug_print, error::*, executor::*, AccessMode, ConnectOptions, DatabaseConnection,
17 DatabaseTransaction, DbBackend, IsolationLevel, QueryStream, Statement, TransactionError,
18};
19
20use super::sqlx_common::*;
21
22#[derive(Debug)]
24pub struct SqlxPostgresConnector;
25
26#[derive(Clone)]
28pub struct SqlxPostgresPoolConnection {
29 pub(crate) pool: PgPool,
30 metric_callback: Option<crate::metric::Callback>,
31}
32
33impl std::fmt::Debug for SqlxPostgresPoolConnection {
34 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35 write!(f, "SqlxPostgresPoolConnection {{ pool: {:?} }}", self.pool)
36 }
37}
38
39impl SqlxPostgresConnector {
40 pub fn accepts(string: &str) -> bool {
42 string.starts_with("postgres://") && string.parse::<PgConnectOptions>().is_ok()
43 }
44
45 #[instrument(level = "trace")]
47 pub async fn connect(options: ConnectOptions) -> Result<DatabaseConnection, DbErr> {
48 let mut opt = options
49 .url
50 .parse::<PgConnectOptions>()
51 .map_err(sqlx_error_to_conn_err)?;
52 use sqlx::ConnectOptions;
53 if !options.sqlx_logging {
54 opt = opt.disable_statement_logging();
55 } else {
56 opt = opt.log_statements(options.sqlx_logging_level);
57 if options.sqlx_slow_statements_logging_level != LevelFilter::Off {
58 opt = opt.log_slow_statements(
59 options.sqlx_slow_statements_logging_level,
60 options.sqlx_slow_statements_logging_threshold,
61 );
62 }
63 }
64 let set_search_path_sql = options
65 .schema_search_path
66 .as_ref()
67 .map(|schema| format!("SET search_path = {schema}"));
68 let lazy = options.connect_lazy;
69 let mut pool_options = options.sqlx_pool_options();
70 if let Some(sql) = set_search_path_sql {
71 pool_options = pool_options.after_connect(move |conn, _| {
72 let sql = sql.clone();
73 Box::pin(async move {
74 sqlx::Executor::execute(conn, sql.as_str())
75 .await
76 .map(|_| ())
77 })
78 });
79 }
80 let pool = if lazy {
81 pool_options.connect_lazy_with(opt)
82 } else {
83 pool_options
84 .connect_with(opt)
85 .await
86 .map_err(sqlx_error_to_conn_err)?
87 };
88 Ok(DatabaseConnection::SqlxPostgresPoolConnection(
89 SqlxPostgresPoolConnection {
90 pool,
91 metric_callback: None,
92 },
93 ))
94 }
95}
96
97impl SqlxPostgresConnector {
98 pub fn from_sqlx_postgres_pool(pool: PgPool) -> DatabaseConnection {
100 DatabaseConnection::SqlxPostgresPoolConnection(SqlxPostgresPoolConnection {
101 pool,
102 metric_callback: None,
103 })
104 }
105}
106
107impl SqlxPostgresPoolConnection {
108 #[instrument(level = "trace")]
110 pub async fn execute(&self, stmt: Statement) -> Result<ExecResult, DbErr> {
111 debug_print!("{}", stmt);
112
113 let query = sqlx_query(&stmt);
114 let mut conn = self.pool.acquire().await.map_err(sqlx_conn_acquire_err)?;
115 crate::metric::metric!(self.metric_callback, &stmt, {
116 match query.execute(&mut *conn).await {
117 Ok(res) => Ok(res.into()),
118 Err(err) => Err(sqlx_error_to_exec_err(err)),
119 }
120 })
121 }
122
123 #[instrument(level = "trace")]
125 pub async fn execute_unprepared(&self, sql: &str) -> Result<ExecResult, DbErr> {
126 debug_print!("{}", sql);
127
128 let conn = &mut self.pool.acquire().await.map_err(sqlx_conn_acquire_err)?;
129 match conn.execute(sql).await {
130 Ok(res) => Ok(res.into()),
131 Err(err) => Err(sqlx_error_to_exec_err(err)),
132 }
133 }
134
135 #[instrument(level = "trace")]
137 pub async fn query_one(&self, stmt: Statement) -> Result<Option<QueryResult>, DbErr> {
138 debug_print!("{}", stmt);
139
140 let query = sqlx_query(&stmt);
141 let mut conn = self.pool.acquire().await.map_err(sqlx_conn_acquire_err)?;
142 crate::metric::metric!(self.metric_callback, &stmt, {
143 match query.fetch_one(&mut *conn).await {
144 Ok(row) => Ok(Some(row.into())),
145 Err(err) => match err {
146 sqlx::Error::RowNotFound => Ok(None),
147 _ => Err(sqlx_error_to_query_err(err)),
148 },
149 }
150 })
151 }
152
153 #[instrument(level = "trace")]
155 pub async fn query_all(&self, stmt: Statement) -> Result<Vec<QueryResult>, DbErr> {
156 debug_print!("{}", stmt);
157
158 let query = sqlx_query(&stmt);
159 let mut conn = self.pool.acquire().await.map_err(sqlx_conn_acquire_err)?;
160 crate::metric::metric!(self.metric_callback, &stmt, {
161 match query.fetch_all(&mut *conn).await {
162 Ok(rows) => Ok(rows.into_iter().map(|r| r.into()).collect()),
163 Err(err) => Err(sqlx_error_to_query_err(err)),
164 }
165 })
166 }
167
168 #[instrument(level = "trace")]
170 pub async fn stream(&self, stmt: Statement) -> Result<QueryStream, DbErr> {
171 debug_print!("{}", stmt);
172
173 let conn = self.pool.acquire().await.map_err(sqlx_conn_acquire_err)?;
174 Ok(QueryStream::from((
175 conn,
176 stmt,
177 self.metric_callback.clone(),
178 )))
179 }
180
181 #[instrument(level = "trace")]
183 pub async fn begin(
184 &self,
185 isolation_level: Option<IsolationLevel>,
186 access_mode: Option<AccessMode>,
187 ) -> Result<DatabaseTransaction, DbErr> {
188 let conn = self.pool.acquire().await.map_err(sqlx_conn_acquire_err)?;
189 DatabaseTransaction::new_postgres(
190 conn,
191 self.metric_callback.clone(),
192 isolation_level,
193 access_mode,
194 )
195 .await
196 }
197
198 #[instrument(level = "trace", skip(callback))]
200 pub async fn transaction<F, T, E>(
201 &self,
202 callback: F,
203 isolation_level: Option<IsolationLevel>,
204 access_mode: Option<AccessMode>,
205 ) -> Result<T, TransactionError<E>>
206 where
207 F: for<'b> FnOnce(
208 &'b DatabaseTransaction,
209 ) -> Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'b>>
210 + Send,
211 T: Send,
212 E: std::error::Error + Send,
213 {
214 let conn = self.pool.acquire().await.map_err(sqlx_conn_acquire_err)?;
215 let transaction = DatabaseTransaction::new_postgres(
216 conn,
217 self.metric_callback.clone(),
218 isolation_level,
219 access_mode,
220 )
221 .await
222 .map_err(|e| TransactionError::Connection(e))?;
223 transaction.run(callback).await
224 }
225
226 pub(crate) fn set_metric_callback<F>(&mut self, callback: F)
227 where
228 F: Fn(&crate::metric::Info<'_>) + Send + Sync + 'static,
229 {
230 self.metric_callback = Some(Arc::new(callback));
231 }
232
233 pub async fn ping(&self) -> Result<(), DbErr> {
235 let conn = &mut self.pool.acquire().await.map_err(sqlx_conn_acquire_err)?;
236 match conn.ping().await {
237 Ok(_) => Ok(()),
238 Err(err) => Err(sqlx_error_to_conn_err(err)),
239 }
240 }
241
242 pub async fn close(self) -> Result<(), DbErr> {
244 self.pool.close().await;
245 Ok(())
246 }
247}
248
249impl From<PgRow> for QueryResult {
250 fn from(row: PgRow) -> QueryResult {
251 QueryResult {
252 row: QueryResultRow::SqlxPostgres(row),
253 }
254 }
255}
256
257impl From<PgQueryResult> for ExecResult {
258 fn from(result: PgQueryResult) -> ExecResult {
259 ExecResult {
260 result: ExecResultHolder::SqlxPostgres(result),
261 }
262 }
263}
264
265pub(crate) fn sqlx_query(stmt: &Statement) -> sqlx::query::Query<'_, Postgres, SqlxValues> {
266 let values = stmt
267 .values
268 .as_ref()
269 .map_or(Values(Vec::new()), |values| values.clone());
270 sqlx::query_with(&stmt.sql, SqlxValues(values))
271}
272
273pub(crate) async fn set_transaction_config(
274 conn: &mut PoolConnection<Postgres>,
275 isolation_level: Option<IsolationLevel>,
276 access_mode: Option<AccessMode>,
277) -> Result<(), DbErr> {
278 if let Some(isolation_level) = isolation_level {
279 let stmt = Statement {
280 sql: format!("SET TRANSACTION ISOLATION LEVEL {isolation_level}"),
281 values: None,
282 db_backend: DbBackend::Postgres,
283 };
284 let query = sqlx_query(&stmt);
285 conn.execute(query).await.map_err(sqlx_error_to_exec_err)?;
286 }
287 if let Some(access_mode) = access_mode {
288 let stmt = Statement {
289 sql: format!("SET TRANSACTION {access_mode}"),
290 values: None,
291 db_backend: DbBackend::Postgres,
292 };
293 let query = sqlx_query(&stmt);
294 conn.execute(query).await.map_err(sqlx_error_to_exec_err)?;
295 }
296 Ok(())
297}
298
299impl
300 From<(
301 PoolConnection<sqlx::Postgres>,
302 Statement,
303 Option<crate::metric::Callback>,
304 )> for crate::QueryStream
305{
306 fn from(
307 (conn, stmt, metric_callback): (
308 PoolConnection<sqlx::Postgres>,
309 Statement,
310 Option<crate::metric::Callback>,
311 ),
312 ) -> Self {
313 crate::QueryStream::build(
314 stmt,
315 crate::InnerConnection::Postgres(conn),
316 metric_callback,
317 )
318 }
319}
320
321impl crate::DatabaseTransaction {
322 pub(crate) async fn new_postgres(
323 inner: PoolConnection<sqlx::Postgres>,
324 metric_callback: Option<crate::metric::Callback>,
325 isolation_level: Option<IsolationLevel>,
326 access_mode: Option<AccessMode>,
327 ) -> Result<crate::DatabaseTransaction, DbErr> {
328 Self::begin(
329 Arc::new(Mutex::new(crate::InnerConnection::Postgres(inner))),
330 crate::DbBackend::Postgres,
331 metric_callback,
332 isolation_level,
333 access_mode,
334 )
335 .await
336 }
337}
338
339#[cfg(feature = "proxy")]
340pub(crate) fn from_sqlx_postgres_row_to_proxy_row(row: &sqlx::postgres::PgRow) -> crate::ProxyRow {
341 use sea_query::Value;
344 use sqlx::{Column, Row, TypeInfo};
345 crate::ProxyRow {
346 values: row
347 .columns()
348 .iter()
349 .map(|c| {
350 (
351 c.name().to_string(),
352 match c.type_info().name() {
353 "BOOL" => Value::Bool(Some(
354 row.try_get(c.ordinal()).expect("Failed to get boolean"),
355 )),
356 #[cfg(feature = "postgres-array")]
357 "BOOL[]" => Value::Array(
358 sea_query::ArrayType::Bool,
359 Some(Box::new(
360 row.try_get::<Vec<bool>, _>(c.ordinal())
361 .expect("Failed to get boolean array")
362 .iter()
363 .map(|val| Value::Bool(Some(*val)))
364 .collect(),
365 )),
366 ),
367
368 "\"CHAR\"" => Value::TinyInt(Some(
369 row.try_get(c.ordinal())
370 .expect("Failed to get small integer"),
371 )),
372 #[cfg(feature = "postgres-array")]
373 "\"CHAR\"[]" => Value::Array(
374 sea_query::ArrayType::TinyInt,
375 Some(Box::new(
376 row.try_get::<Vec<i8>, _>(c.ordinal())
377 .expect("Failed to get small integer array")
378 .iter()
379 .map(|val| Value::TinyInt(Some(*val)))
380 .collect(),
381 )),
382 ),
383
384 "SMALLINT" | "SMALLSERIAL" | "INT2" => Value::SmallInt(Some(
385 row.try_get(c.ordinal())
386 .expect("Failed to get small integer"),
387 )),
388 #[cfg(feature = "postgres-array")]
389 "SMALLINT[]" | "SMALLSERIAL[]" | "INT2[]" => Value::Array(
390 sea_query::ArrayType::SmallInt,
391 Some(Box::new(
392 row.try_get::<Vec<i16>, _>(c.ordinal())
393 .expect("Failed to get small integer array")
394 .iter()
395 .map(|val| Value::SmallInt(Some(*val)))
396 .collect(),
397 )),
398 ),
399
400 "INT" | "SERIAL" | "INT4" => Value::Int(Some(
401 row.try_get(c.ordinal()).expect("Failed to get integer"),
402 )),
403 #[cfg(feature = "postgres-array")]
404 "INT[]" | "SERIAL[]" | "INT4[]" => Value::Array(
405 sea_query::ArrayType::Int,
406 Some(Box::new(
407 row.try_get::<Vec<i32>, _>(c.ordinal())
408 .expect("Failed to get integer array")
409 .iter()
410 .map(|val| Value::Int(Some(*val)))
411 .collect(),
412 )),
413 ),
414
415 "BIGINT" | "BIGSERIAL" | "INT8" => Value::BigInt(Some(
416 row.try_get(c.ordinal()).expect("Failed to get big integer"),
417 )),
418 #[cfg(feature = "postgres-array")]
419 "BIGINT[]" | "BIGSERIAL[]" | "INT8[]" => Value::Array(
420 sea_query::ArrayType::BigInt,
421 Some(Box::new(
422 row.try_get::<Vec<i64>, _>(c.ordinal())
423 .expect("Failed to get big integer array")
424 .iter()
425 .map(|val| Value::BigInt(Some(*val)))
426 .collect(),
427 )),
428 ),
429
430 "FLOAT4" | "REAL" => Value::Float(Some(
431 row.try_get(c.ordinal()).expect("Failed to get float"),
432 )),
433 #[cfg(feature = "postgres-array")]
434 "FLOAT4[]" | "REAL[]" => Value::Array(
435 sea_query::ArrayType::Float,
436 Some(Box::new(
437 row.try_get::<Vec<f32>, _>(c.ordinal())
438 .expect("Failed to get float array")
439 .iter()
440 .map(|val| Value::Float(Some(*val)))
441 .collect(),
442 )),
443 ),
444
445 "FLOAT8" | "DOUBLE PRECISION" => Value::Double(Some(
446 row.try_get(c.ordinal()).expect("Failed to get double"),
447 )),
448 #[cfg(feature = "postgres-array")]
449 "FLOAT8[]" | "DOUBLE PRECISION[]" => Value::Array(
450 sea_query::ArrayType::Double,
451 Some(Box::new(
452 row.try_get::<Vec<f64>, _>(c.ordinal())
453 .expect("Failed to get double array")
454 .iter()
455 .map(|val| Value::Double(Some(*val)))
456 .collect(),
457 )),
458 ),
459
460 "VARCHAR" | "CHAR" | "TEXT" | "NAME" => Value::String(Some(Box::new(
461 row.try_get(c.ordinal()).expect("Failed to get string"),
462 ))),
463 #[cfg(feature = "postgres-array")]
464 "VARCHAR[]" | "CHAR[]" | "TEXT[]" | "NAME[]" => Value::Array(
465 sea_query::ArrayType::String,
466 Some(Box::new(
467 row.try_get::<Vec<String>, _>(c.ordinal())
468 .expect("Failed to get string array")
469 .iter()
470 .map(|val| Value::String(Some(Box::new(val.clone()))))
471 .collect(),
472 )),
473 ),
474
475 "BYTEA" => Value::Bytes(Some(Box::new(
476 row.try_get(c.ordinal()).expect("Failed to get bytes"),
477 ))),
478 #[cfg(feature = "postgres-array")]
479 "BYTEA[]" => Value::Array(
480 sea_query::ArrayType::Bytes,
481 Some(Box::new(
482 row.try_get::<Vec<Vec<u8>>, _>(c.ordinal())
483 .expect("Failed to get bytes array")
484 .iter()
485 .map(|val| Value::Bytes(Some(Box::new(val.clone()))))
486 .collect(),
487 )),
488 ),
489
490 #[cfg(feature = "with-bigdecimal")]
491 "NUMERIC" => Value::BigDecimal(Some(Box::new(
492 row.try_get(c.ordinal()).expect("Failed to get numeric"),
493 ))),
494 #[cfg(all(
495 feature = "with-rust_decimal",
496 not(feature = "with-bigdecimal")
497 ))]
498 "NUMERIC" => Value::Decimal(Some(Box::new(
499 row.try_get(c.ordinal()).expect("Failed to get numeric"),
500 ))),
501
502 #[cfg(all(feature = "with-bigdecimal", feature = "postgres-array"))]
503 "NUMERIC[]" => Value::Array(
504 sea_query::ArrayType::BigDecimal,
505 Some(Box::new(
506 row.try_get::<Vec<bigdecimal::BigDecimal>, _>(c.ordinal())
507 .expect("Failed to get numeric array")
508 .iter()
509 .map(|val| Value::BigDecimal(Some(Box::new(val.clone()))))
510 .collect(),
511 )),
512 ),
513 #[cfg(all(
514 feature = "with-rust_decimal",
515 not(feature = "with-bigdecimal"),
516 feature = "postgres-array"
517 ))]
518 "NUMERIC[]" => Value::Array(
519 sea_query::ArrayType::Decimal,
520 Some(Box::new(
521 row.try_get::<Vec<rust_decimal::Decimal>, _>(c.ordinal())
522 .expect("Failed to get numeric array")
523 .iter()
524 .map(|val| Value::Decimal(Some(Box::new(val.clone()))))
525 .collect(),
526 )),
527 ),
528
529 "OID" => Value::BigInt(Some(
530 row.try_get(c.ordinal()).expect("Failed to get oid"),
531 )),
532 #[cfg(feature = "postgres-array")]
533 "OID[]" => Value::Array(
534 sea_query::ArrayType::BigInt,
535 Some(Box::new(
536 row.try_get::<Vec<i64>, _>(c.ordinal())
537 .expect("Failed to get oid array")
538 .iter()
539 .map(|val| Value::BigInt(Some(*val)))
540 .collect(),
541 )),
542 ),
543
544 "JSON" | "JSONB" => Value::Json(Some(Box::new(
545 row.try_get(c.ordinal()).expect("Failed to get json"),
546 ))),
547 #[cfg(any(feature = "json-array", feature = "postgres-array"))]
548 "JSON[]" | "JSONB[]" => Value::Array(
549 sea_query::ArrayType::Json,
550 Some(Box::new(
551 row.try_get::<Vec<serde_json::Value>, _>(c.ordinal())
552 .expect("Failed to get json array")
553 .iter()
554 .map(|val| Value::Json(Some(Box::new(val.clone()))))
555 .collect(),
556 )),
557 ),
558
559 #[cfg(feature = "with-ipnetwork")]
560 "INET" | "CIDR" => Value::IpNetwork(Some(Box::new(
561 row.try_get(c.ordinal()).expect("Failed to get ip address"),
562 ))),
563 #[cfg(feature = "with-ipnetwork")]
564 "INET[]" | "CIDR[]" => Value::Array(
565 sea_query::ArrayType::IpNetwork,
566 Some(Box::new(
567 row.try_get::<Vec<ipnetwork::IpNetwork>, _>(c.ordinal())
568 .expect("Failed to get ip address array")
569 .iter()
570 .map(|val| Value::IpNetwork(Some(Box::new(val.clone()))))
571 .collect(),
572 )),
573 ),
574
575 #[cfg(feature = "with-mac_address")]
576 "MACADDR" | "MACADDR8" => Value::MacAddress(Some(Box::new(
577 row.try_get(c.ordinal()).expect("Failed to get mac address"),
578 ))),
579 #[cfg(all(feature = "with-mac_address", feature = "postgres-array"))]
580 "MACADDR[]" | "MACADDR8[]" => Value::Array(
581 sea_query::ArrayType::MacAddress,
582 Some(Box::new(
583 row.try_get::<Vec<mac_address::MacAddress>, _>(c.ordinal())
584 .expect("Failed to get mac address array")
585 .iter()
586 .map(|val| Value::MacAddress(Some(Box::new(val.clone()))))
587 .collect(),
588 )),
589 ),
590
591 #[cfg(feature = "with-chrono")]
592 "TIMESTAMP" => Value::ChronoDateTime(Some(Box::new(
593 row.try_get(c.ordinal()).expect("Failed to get timestamp"),
594 ))),
595 #[cfg(all(feature = "with-time", not(feature = "with-chrono")))]
596 "TIMESTAMP" => Value::TimeDateTime(Some(Box::new(
597 row.try_get(c.ordinal()).expect("Failed to get timestamp"),
598 ))),
599
600 #[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
601 "TIMESTAMP[]" => Value::Array(
602 sea_query::ArrayType::ChronoDateTime,
603 Some(Box::new(
604 row.try_get::<Vec<chrono::NaiveDateTime>, _>(c.ordinal())
605 .expect("Failed to get timestamp array")
606 .iter()
607 .map(|val| Value::ChronoDateTime(Some(Box::new(val.clone()))))
608 .collect(),
609 )),
610 ),
611 #[cfg(all(
612 feature = "with-time",
613 not(feature = "with-chrono"),
614 feature = "postgres-array"
615 ))]
616 "TIMESTAMP[]" => Value::Array(
617 sea_query::ArrayType::TimeDateTime,
618 Some(Box::new(
619 row.try_get::<Vec<time::OffsetDateTime>, _>(c.ordinal())
620 .expect("Failed to get timestamp array")
621 .iter()
622 .map(|val| Value::TimeDateTime(Some(Box::new(val.clone()))))
623 .collect(),
624 )),
625 ),
626
627 #[cfg(feature = "with-chrono")]
628 "DATE" => Value::ChronoDate(Some(Box::new(
629 row.try_get(c.ordinal()).expect("Failed to get date"),
630 ))),
631 #[cfg(all(feature = "with-time", not(feature = "with-chrono")))]
632 "DATE" => Value::TimeDate(Some(Box::new(
633 row.try_get(c.ordinal()).expect("Failed to get date"),
634 ))),
635
636 #[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
637 "DATE[]" => Value::Array(
638 sea_query::ArrayType::ChronoDate,
639 Some(Box::new(
640 row.try_get::<Vec<chrono::NaiveDate>, _>(c.ordinal())
641 .expect("Failed to get date array")
642 .iter()
643 .map(|val| Value::ChronoDate(Some(Box::new(val.clone()))))
644 .collect(),
645 )),
646 ),
647 #[cfg(all(
648 feature = "with-time",
649 not(feature = "with-chrono"),
650 feature = "postgres-array"
651 ))]
652 "DATE[]" => Value::Array(
653 sea_query::ArrayType::TimeDate,
654 Some(Box::new(
655 row.try_get::<Vec<time::Date>, _>(c.ordinal())
656 .expect("Failed to get date array")
657 .iter()
658 .map(|val| Value::TimeDate(Some(Box::new(val.clone()))))
659 .collect(),
660 )),
661 ),
662
663 #[cfg(feature = "with-chrono")]
664 "TIME" => Value::ChronoTime(Some(Box::new(
665 row.try_get(c.ordinal()).expect("Failed to get time"),
666 ))),
667 #[cfg(all(feature = "with-time", not(feature = "with-chrono")))]
668 "TIME" => Value::TimeTime(Some(Box::new(
669 row.try_get(c.ordinal()).expect("Failed to get time"),
670 ))),
671
672 #[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
673 "TIME[]" => Value::Array(
674 sea_query::ArrayType::ChronoTime,
675 Some(Box::new(
676 row.try_get::<Vec<chrono::NaiveTime>, _>(c.ordinal())
677 .expect("Failed to get time array")
678 .iter()
679 .map(|val| Value::ChronoTime(Some(Box::new(val.clone()))))
680 .collect(),
681 )),
682 ),
683 #[cfg(all(
684 feature = "with-time",
685 not(feature = "with-chrono"),
686 feature = "postgres-array"
687 ))]
688 "TIME[]" => Value::Array(
689 sea_query::ArrayType::TimeTime,
690 Some(Box::new(
691 row.try_get::<Vec<time::Time>, _>(c.ordinal())
692 .expect("Failed to get time array")
693 .iter()
694 .map(|val| Value::TimeTime(Some(Box::new(val.clone()))))
695 .collect(),
696 )),
697 ),
698
699 #[cfg(feature = "with-chrono")]
700 "TIMESTAMPTZ" => Value::ChronoDateTimeUtc(Some(Box::new(
701 row.try_get(c.ordinal()).expect("Failed to get timestamptz"),
702 ))),
703 #[cfg(all(feature = "with-time", not(feature = "with-chrono")))]
704 "TIMESTAMPTZ" => Value::TimeDateTime(Some(Box::new(
705 row.try_get(c.ordinal()).expect("Failed to get timestamptz"),
706 ))),
707
708 #[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
709 "TIMESTAMPTZ[]" => Value::Array(
710 sea_query::ArrayType::ChronoDateTimeUtc,
711 Some(Box::new(
712 row.try_get::<Vec<chrono::DateTime<chrono::Utc>>, _>(c.ordinal())
713 .expect("Failed to get timestamptz array")
714 .iter()
715 .map(|val| {
716 Value::ChronoDateTimeUtc(Some(Box::new(val.clone())))
717 })
718 .collect(),
719 )),
720 ),
721 #[cfg(all(
722 feature = "with-time",
723 not(feature = "with-chrono"),
724 feature = "postgres-array"
725 ))]
726 "TIMESTAMPTZ[]" => Value::Array(
727 sea_query::ArrayType::TimeDateTime,
728 Some(Box::new(
729 row.try_get::<Vec<time::OffsetDateTime>, _>(c.ordinal())
730 .expect("Failed to get timestamptz array")
731 .iter()
732 .map(|val| Value::TimeDateTime(Some(Box::new(val.clone()))))
733 .collect(),
734 )),
735 ),
736
737 #[cfg(feature = "with-chrono")]
738 "TIMETZ" => Value::ChronoTime(Some(Box::new(
739 row.try_get(c.ordinal()).expect("Failed to get timetz"),
740 ))),
741 #[cfg(all(feature = "with-time", not(feature = "with-chrono")))]
742 "TIMETZ" => Value::TimeTime(Some(Box::new(
743 row.try_get(c.ordinal()).expect("Failed to get timetz"),
744 ))),
745
746 #[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
747 "TIMETZ[]" => Value::Array(
748 sea_query::ArrayType::ChronoTime,
749 Some(Box::new(
750 row.try_get::<Vec<chrono::NaiveTime>, _>(c.ordinal())
751 .expect("Failed to get timetz array")
752 .iter()
753 .map(|val| Value::ChronoTime(Some(Box::new(val.clone()))))
754 .collect(),
755 )),
756 ),
757 #[cfg(all(
758 feature = "with-time",
759 not(feature = "with-chrono"),
760 feature = "postgres-array"
761 ))]
762 "TIMETZ[]" => Value::Array(
763 sea_query::ArrayType::TimeTime,
764 Some(Box::new(
765 row.try_get::<Vec<time::Time>, _>(c.ordinal())
766 .expect("Failed to get timetz array")
767 .iter()
768 .map(|val| Value::TimeTime(Some(Box::new(val.clone()))))
769 .collect(),
770 )),
771 ),
772
773 #[cfg(feature = "with-uuid")]
774 "UUID" => Value::Uuid(Some(Box::new(
775 row.try_get(c.ordinal()).expect("Failed to get uuid"),
776 ))),
777
778 #[cfg(all(feature = "with-uuid", feature = "postgres-array"))]
779 "UUID[]" => Value::Array(
780 sea_query::ArrayType::Uuid,
781 Some(Box::new(
782 row.try_get::<Vec<uuid::Uuid>, _>(c.ordinal())
783 .expect("Failed to get uuid array")
784 .iter()
785 .map(|val| Value::Uuid(Some(Box::new(val.clone()))))
786 .collect(),
787 )),
788 ),
789
790 _ => unreachable!("Unknown column type: {}", c.type_info().name()),
791 },
792 )
793 })
794 .collect(),
795 }
796}