Source File
order_by.go
Belonging Package
gorm.io/gorm/clause
package clause
type OrderByColumn struct {
Column Column
Desc bool
Reorder bool
}
type OrderBy struct {
Columns []OrderByColumn
Expression Expression
}
// Name where clause name
func ( OrderBy) () string {
return "ORDER BY"
}
// Build build where clause
func ( OrderBy) ( Builder) {
if .Expression != nil {
.Expression.Build()
} else {
for , := range .Columns {
if > 0 {
.WriteByte(',')
}
.WriteQuoted(.Column)
if .Desc {
.WriteString(" DESC")
}
}
}
}
// MergeClause merge order by clauses
func ( OrderBy) ( *Clause) {
if , := .Expression.(OrderBy); {
for := len(.Columns) - 1; >= 0; -- {
if .Columns[].Reorder {
.Columns = .Columns[:]
.Expression =
return
}
}
:= make([]OrderByColumn, len(.Columns))
copy(, .Columns)
.Columns = append(, .Columns...)
}
.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. |