Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add offset and limit #351

Merged
merged 2 commits into from
Dec 2, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/query/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,40 @@ pub trait QueryOrder: Sized {
.order_by_expr(col.into_simple_expr(), Order::Desc);
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
}
billy1624 marked this conversation as resolved.
Show resolved Hide resolved
}

// LINT: when the column does not appear in tables selected from
Expand Down