1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
use query_builder::AsQuery;
use query_source::Table;

/// Sets the limit clause of a query. If there was already a limit clause, it
/// will be overridden. This is automatically implemented for the various query
/// builder types.
pub trait LimitDsl: AsQuery {
    type Output: AsQuery<SqlType=Self::SqlType>;

    fn limit(self, limit: i64) -> Self::Output;
}

impl<T, ST> LimitDsl for T where
    T: Table + AsQuery<SqlType=ST>,
    T::Query: LimitDsl<SqlType=ST>,
{
    type Output = <T::Query as LimitDsl>::Output;

    fn limit(self, limit: i64) -> Self::Output {
        self.as_query().limit(limit)
    }
}