Source File
limit.go
Belonging Package
gorm.io/gorm/clause
package clause
import
// Limit limit clause
type Limit struct {
Limit *int
Offset int
}
// Name where clause name
func ( Limit) () string {
return "LIMIT"
}
// Build build where clause
func ( Limit) ( Builder) {
if .Limit != nil && *.Limit >= 0 {
.WriteString("LIMIT ")
.WriteString(strconv.Itoa(*.Limit))
}
if .Offset > 0 {
if .Limit != nil && *.Limit >= 0 {
.WriteByte(' ')
}
.WriteString("OFFSET ")
.WriteString(strconv.Itoa(.Offset))
}
}
// MergeClause merge order by clauses
func ( Limit) ( *Clause) {
.Name = ""
if , := .Expression.(Limit); {
if (.Limit == nil || *.Limit == 0) && .Limit != nil {
.Limit = .Limit
}
if .Offset == 0 && .Offset > 0 {
.Offset = .Offset
} else if .Offset < 0 {
.Offset = 0
}
}
.Expression =
}
![]() |
The pages are generated with Golds v0.6.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |