github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/kit/sqlx/builder/builder_addition_limit.go (about) 1 package builder 2 3 import ( 4 "context" 5 "strconv" 6 ) 7 8 type limit struct { 9 count int64 10 offset int64 11 AdditionType 12 } 13 14 func Limit(count int64) *limit { return &limit{AdditionType: AdditionLimit, count: count} } 15 16 func (l limit) Offset(offset int64) *limit { l.offset = offset; return &l } 17 18 func (l *limit) IsNil() bool { return l == nil || l.count <= 0 } 19 20 func (l *limit) Ex(ctx context.Context) *Ex { 21 e := ExactlyExpr("LIMIT ") 22 e.WriteQuery(strconv.FormatInt(l.count, 10)) 23 if l.offset > 0 { 24 e.WriteQuery(" OFFSET ") 25 e.WriteQuery(strconv.FormatInt(l.offset, 10)) 26 } 27 return e.Ex(ctx) 28 }