SetOffset returns a Rule that sets (or replaces) the OFFSET clause of a SELECT statement. Use together with SetLimit to implement pagination. Parameters: - n: Number of rows to skip; must be >= 0. Returns an error for negative values. Returns ErrUnsupportedStatement for non-SELECT statements.
(n int)
| 49 | // |
| 50 | // Returns ErrUnsupportedStatement for non-SELECT statements. |
| 51 | func SetOffset(n int) Rule { |
| 52 | return RuleFunc(func(stmt ast.Statement) error { |
| 53 | if n < 0 { |
| 54 | return fmt.Errorf("SetOffset: value must be non-negative, got %d", n) |
| 55 | } |
| 56 | sel, err := getSelect(stmt, "SetOffset") |
| 57 | if err != nil { |
| 58 | return err |
| 59 | } |
| 60 | sel.Offset = &n |
| 61 | return nil |
| 62 | }) |
| 63 | } |
| 64 | |
| 65 | // RemoveLimit returns a Rule that removes the LIMIT clause from a SELECT statement, |
| 66 | // allowing the query to return an unbounded number of rows. |