Skip to content

Commit

Permalink
add offset and limit (#351)
Browse files Browse the repository at this point in the history
* add offset and limit

* move offset&limit to QuerySelect
  • Loading branch information
lz1998 authored Dec 2, 2021
1 parent cc49049 commit 273dc0d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/query/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,40 @@ pub trait QuerySelect: Sized {
self
}

/// Add an offset expression
/// ```
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
///
/// assert_eq!(
/// cake::Entity::find()
/// .offset(10)
/// .build(DbBackend::MySql)
/// .to_string(),
/// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` OFFSET 10"
/// );
/// ```
fn offset(mut self, offset: u64) -> Self {
self.query().offset(offset);
self
}

/// Add a limit expression
/// ```
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
///
/// assert_eq!(
/// cake::Entity::find()
/// .limit(10)
/// .build(DbBackend::MySql)
/// .to_string(),
/// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` LIMIT 10"
/// );
/// ```
fn limit(mut self, limit: u64) -> Self {
self.query().limit(limit);
self
}

/// Add a group by column
/// ```
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
Expand Down

0 comments on commit 273dc0d

Please sign in to comment.