Electron100 / butane

An ORM for Rust with a focus on simplicity and on writing Rust, not SQL
Apache License 2.0
93 stars 13 forks source link

Add offset parameter #10

Closed DimmKG closed 3 years ago

DimmKG commented 3 years ago

Offset allows you to skip a certain number of records before returning the result. This can be useful when requesting the next page of records if a limit is set.

Example

pub fn article_list(limit: i32, offset: i32, conn: &Connection) -> Result<Vec<ArticleOutput>, Error>
{
    let res = Query::<Article>::new("article")
        .limit(limit)
        .offset(offset)
        .load(conn);
    match res {
        Ok(articles) => {
            let mut result : Vec<ArticleOutput> = vec!();
            for article in articles {
                result.push(article.to_result(conn));
            }
            Ok(result)
        },
        Err(err) => return Err(err)
    }
}