MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / SetLimit

Function SetLimit

pkg/transform/limit.go:30–42  ·  view source on GitHub ↗

SetLimit returns a Rule that sets (or replaces) the LIMIT clause of a SELECT statement. Any existing LIMIT value is overwritten. Parameters: - n: Number of rows to return; must be >= 0. Returns an error for negative values. Returns ErrUnsupportedStatement for non-SELECT statements.

(n int)

Source from the content-addressed store, hash-verified

28//
29// Returns ErrUnsupportedStatement for non-SELECT statements.
30func SetLimit(n int) Rule {
31 return RuleFunc(func(stmt ast.Statement) error {
32 if n < 0 {
33 return fmt.Errorf("SetLimit: value must be non-negative, got %d", n)
34 }
35 sel, err := getSelect(stmt, "SetLimit")
36 if err != nil {
37 return err
38 }
39 sel.Limit = &n
40 return nil
41 })
42}
43
44// SetOffset returns a Rule that sets (or replaces) the OFFSET clause of a SELECT
45// statement. Use together with SetLimit to implement pagination.

Calls 3

RuleFuncFuncType · 0.85
getSelectFunction · 0.85
ErrorfMethod · 0.65