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

Function SetOffset

pkg/transform/limit.go:51–63  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

49//
50// Returns ErrUnsupportedStatement for non-SELECT statements.
51func 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.

Callers 7

mainFunction · 0.92
TestComposabilityFunction · 0.85
TestSetOffsetFunction · 0.85
TestSetOffset_ZeroFunction · 0.85
TestSetOffset_NegativeFunction · 0.85

Calls 3

RuleFuncFuncType · 0.85
getSelectFunction · 0.85
ErrorfMethod · 0.65

Tested by 6

TestComposabilityFunction · 0.68
TestSetOffsetFunction · 0.68
TestSetOffset_ZeroFunction · 0.68
TestSetOffset_NegativeFunction · 0.68