github.com/eden-framework/sqlx@v0.0.2/builder/addition_limit.go (about) 1 package builder 2 3 import ( 4 "context" 5 "strconv" 6 ) 7 8 type LimitAddition struct { 9 } 10 11 func (LimitAddition) AdditionType() AdditionType { 12 return AdditionLimit 13 } 14 15 func Limit(rowCount int64) *limit { 16 return &limit{rowCount: rowCount} 17 } 18 19 var _ Addition = (*limit)(nil) 20 21 type limit struct { 22 LimitAddition 23 24 // LIMIT 25 rowCount int64 26 // OFFSET 27 offsetCount int64 28 } 29 30 func (l limit) Offset(offset int64) *limit { 31 l.offsetCount = offset 32 return &l 33 } 34 35 func (l *limit) IsNil() bool { 36 return l == nil || l.rowCount <= 0 37 } 38 39 func (l *limit) Ex(ctx context.Context) *Ex { 40 e := Expr("LIMIT ") 41 42 e.WriteString(strconv.FormatInt(l.rowCount, 10)) 43 44 if l.offsetCount > 0 { 45 e.WriteString(" OFFSET ") 46 e.WriteString(strconv.FormatInt(l.offsetCount, 10)) 47 } 48 49 return e.Ex(ctx) 50 }