Skip to main content

diesel/pg/query_builder/
limit_offset.rs

1use crate::pg::Pg;
2use crate::query_builder::limit_offset_clause::{
3    BoxedCloneLimitOffsetClause, BoxedLimitOffsetClause, LimitOffsetClause,
4};
5use crate::query_builder::{AstPass, IntoBoxedClause, IntoBoxedCloneClause, QueryFragment};
6use crate::result::QueryResult;
7use alloc::sync::Arc;
8
9impl<'a, L, O> IntoBoxedCloneClause<'a, Pg> for LimitOffsetClause<L, O>
10where
11    L: QueryFragment<Pg> + Send + Sync + 'a,
12    O: QueryFragment<Pg> + Send + Sync + 'a,
13{
14    type BoxedCloneClause = BoxedCloneLimitOffsetClause<'a, Pg>;
15
16    fn into_boxed_clone(self) -> Self::BoxedCloneClause {
17        BoxedCloneLimitOffsetClause {
18            limit: Some(Arc::new(self.limit_clause)),
19            offset: Some(Arc::new(self.offset_clause)),
20        }
21    }
22}
23
24impl QueryFragment<Pg> for BoxedCloneLimitOffsetClause<'_, Pg> {
25    fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, Pg>) -> QueryResult<()> {
26        if let Some(ref limit) = self.limit {
27            limit.walk_ast(out.reborrow())?;
28        }
29        if let Some(ref offset) = self.offset {
30            offset.walk_ast(out.reborrow())?;
31        }
32        Ok(())
33    }
34}
35
36impl<'a, L, O> IntoBoxedClause<'a, Pg> for LimitOffsetClause<L, O>
37where
38    L: QueryFragment<Pg> + Send + 'a,
39    O: QueryFragment<Pg> + Send + 'a,
40{
41    type BoxedClause = BoxedLimitOffsetClause<'a, Pg>;
42
43    fn into_boxed(self) -> Self::BoxedClause {
44        BoxedLimitOffsetClause {
45            limit: Some(Box::new(self.limit_clause)),
46            offset: Some(Box::new(self.offset_clause)),
47        }
48    }
49}
50
51impl QueryFragment<Pg> for BoxedLimitOffsetClause<'_, Pg> {
52    fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, Pg>) -> QueryResult<()> {
53        if let Some(ref limit) = self.limit {
54            limit.walk_ast(out.reborrow())?;
55        }
56        if let Some(ref offset) = self.offset {
57            offset.walk_ast(out.reborrow())?;
58        }
59        Ok(())
60    }
61}
62
63impl<L, O> QueryFragment<Pg> for LimitOffsetClause<L, O>
64where
65    L: QueryFragment<Pg>,
66    O: QueryFragment<Pg>,
67{
68    fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, Pg>) -> QueryResult<()> {
69        self.limit_clause.walk_ast(out.reborrow())?;
70        self.offset_clause.walk_ast(out.reborrow())?;
71        Ok(())
72    }
73}