Skip to content

Commit

Permalink
move this into pg-only land
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed Nov 16, 2017
1 parent a01b020 commit 290221a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 70 deletions.
65 changes: 0 additions & 65 deletions diesel/src/expression/functions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use std::marker::PhantomData;
use expression::{AppearsOnTable, Expression, IntoSingleTypeExpressionList, SelectableExpression};

#[macro_export]
#[doc(hidden)]
macro_rules! sql_function_body {
Expand Down Expand Up @@ -202,68 +199,6 @@ macro_rules! no_arg_sql_function {
};
}

#[derive(Debug)]
pub struct Array<T, ST> {
elements: T,
_marker: PhantomData<ST>,
}

pub fn array<ST, T>(elements: T) -> Array<T::Expression, ST>
where
T: IntoSingleTypeExpressionList<ST>,
{
Array {
elements: elements.into_single_type_expression_list(),
_marker: PhantomData,
}
}

impl<T, ST> Expression for Array<T, ST>
where
T: Expression,
{
type SqlType = ::pg::types::sql_types::Array<ST>;
}

use query_builder::{AstPass, QueryFragment};
use backend::Backend;

impl<T, ST, DB> QueryFragment<DB> for Array<T, ST>
where
DB: Backend,
for<'a> (&'a T): QueryFragment<DB>,
{
fn walk_ast(&self, mut out: AstPass<DB>) -> ::result::QueryResult<()> {
out.push_sql("ARRAY[");
QueryFragment::walk_ast(&(&self.elements,), out.reborrow())?;
out.push_sql("]");
Ok(())
}
}

impl_query_id!(Array<T, ST>);

impl<T, ST, QS> SelectableExpression<QS> for Array<T, ST>
where
T: SelectableExpression<QS>,
Array<T, ST>: AppearsOnTable<QS>,
{
}

impl<T, ST, QS> AppearsOnTable<QS> for Array<T, ST>
where
T: AppearsOnTable<QS>,
Array<T, ST>: Expression,
{
}

impl<T, ST> ::expression::NonAggregate for Array<T, ST>
where
T: ::expression::NonAggregate,
Array<T, ST>: Expression,
{
}

pub mod aggregate_ordering;
pub mod aggregate_folding;
pub mod date_and_time;
5 changes: 0 additions & 5 deletions diesel/src/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ pub mod dsl {

#[cfg(feature = "postgres")]
pub use pg::expression::dsl::*;

#[cfg(feature = "postgres")]
#[doc(inline)]
pub use super::functions::array;

}

#[doc(inline)]
Expand Down
64 changes: 64 additions & 0 deletions diesel/src/pg/expression/array.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use std::marker::PhantomData;
use expression::{AppearsOnTable, Expression, IntoSingleTypeExpressionList, SelectableExpression};

#[derive(Debug)]
pub struct Array<T, ST> {
elements: T,
_marker: PhantomData<ST>,
}

pub fn array<ST, T>(elements: T) -> Array<T::Expression, ST>
where
T: IntoSingleTypeExpressionList<ST>,
{
Array {
elements: elements.into_single_type_expression_list(),
_marker: PhantomData,
}
}

impl<T, ST> Expression for Array<T, ST>
where
T: Expression,
{
type SqlType = ::pg::types::sql_types::Array<ST>;
}

use query_builder::{AstPass, QueryFragment};
use backend::Backend;

impl<T, ST, DB> QueryFragment<DB> for Array<T, ST>
where
DB: Backend,
for<'a> (&'a T): QueryFragment<DB>,
{
fn walk_ast(&self, mut out: AstPass<DB>) -> ::result::QueryResult<()> {
out.push_sql("ARRAY[");
QueryFragment::walk_ast(&(&self.elements,), out.reborrow())?;
out.push_sql("]");
Ok(())
}
}

impl_query_id!(Array<T, ST>);

impl<T, ST, QS> SelectableExpression<QS> for Array<T, ST>
where
T: SelectableExpression<QS>,
Array<T, ST>: AppearsOnTable<QS>,
{
}

impl<T, ST, QS> AppearsOnTable<QS> for Array<T, ST>
where
T: AppearsOnTable<QS>,
Array<T, ST>: Expression,
{
}

impl<T, ST> ::expression::NonAggregate for Array<T, ST>
where
T: ::expression::NonAggregate,
Array<T, ST>: Expression,
{
}
5 changes: 5 additions & 0 deletions diesel/src/pg/expression/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#[doc(hidden)]
pub mod array_comparison;
#[doc(hidden)]
pub mod array;
pub mod expression_methods;
pub mod extensions;
#[doc(hidden)]
Expand All @@ -16,5 +18,8 @@ pub mod dsl {
#[doc(inline)]
pub use super::array_comparison::{all, any};

#[doc(inline)]
pub use super::array::array;

pub use super::extensions::*;
}

0 comments on commit 290221a

Please sign in to comment.