diesel/pg/expression/
array.rs
1use crate::expression::{
2 AppearsOnTable, AsExpressionList, Expression, SelectableExpression, ValidGrouping,
3};
4use crate::pg::Pg;
5use crate::query_builder::{AstPass, QueryFragment, QueryId};
6use crate::sql_types;
7use std::marker::PhantomData;
8
9#[derive(Debug, Clone, Copy, QueryId)]
11pub struct ArrayLiteral<T, ST> {
12 elements: T,
13 _marker: PhantomData<ST>,
14}
15
16#[cfg(feature = "postgres_backend")]
50pub fn array<ST, T>(elements: T) -> ArrayLiteral<T::Expression, ST>
51where
52 T: AsExpressionList<ST>,
53{
54 ArrayLiteral {
55 elements: elements.as_expression_list(),
56 _marker: PhantomData,
57 }
58}
59
60impl<T, ST> Expression for ArrayLiteral<T, ST>
61where
62 ST: 'static,
63 T: Expression,
64{
65 type SqlType = sql_types::Array<ST>;
66}
67
68impl<T, ST> QueryFragment<Pg> for ArrayLiteral<T, ST>
69where
70 T: QueryFragment<Pg>,
71{
72 fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, Pg>) -> crate::result::QueryResult<()> {
73 out.push_sql("ARRAY[");
74 QueryFragment::walk_ast(&self.elements, out.reborrow())?;
75 out.push_sql("]");
76 Ok(())
77 }
78}
79
80impl<T, ST, QS> SelectableExpression<QS> for ArrayLiteral<T, ST>
81where
82 T: SelectableExpression<QS>,
83 ArrayLiteral<T, ST>: AppearsOnTable<QS>,
84{
85}
86
87impl<T, ST, QS> AppearsOnTable<QS> for ArrayLiteral<T, ST>
88where
89 T: AppearsOnTable<QS>,
90 ArrayLiteral<T, ST>: Expression,
91{
92}
93
94impl<T, ST, GB> ValidGrouping<GB> for ArrayLiteral<T, ST>
95where
96 T: ValidGrouping<GB>,
97{
98 type IsAggregate = T::IsAggregate;
99}