gitee.com/h79/goutils@v1.22.10/dao/wrapper/limit.go (about) 1 package wrapper 2 3 import ( 4 commonoption "gitee.com/h79/goutils/common/option" 5 "strings" 6 ) 7 8 var _ ILimit = (*Limit)(nil) 9 10 type Limit struct { 11 Offset int 12 Limit int 13 } 14 15 func (l *Limit) Is() bool { 16 return l.Limit > 0 17 } 18 19 func (l *Limit) GetLimit() int { 20 return l.Limit 21 } 22 23 func (l *Limit) GetOffset() int { 24 return l.Offset 25 } 26 27 func (l *Limit) Build(opts ...commonoption.Option) string { 28 builder := strings.Builder{} 29 if l.Limit > 0 { 30 builder.WriteString(" LIMIT ") 31 AddVar(&builder, l.Limit) 32 } 33 if l.Offset > 0 { 34 builder.WriteString(" OFFSET ") 35 AddVar(&builder, l.Offset) 36 } 37 return builder.String() 38 }