feat: chainable order support clause.OrderBy (#7054)

* feat: chainable order support clause.OrderBy

* indent
This commit is contained in:
supergem3000 2024-06-12 17:47:34 +08:00 committed by GitHub
parent 49d94c173c
commit 49d524aaea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 0 deletions

View File

@ -299,10 +299,16 @@ func (db *DB) Having(query interface{}, args ...interface{}) (tx *DB) {
//
// db.Order("name DESC")
// db.Order(clause.OrderByColumn{Column: clause.Column{Name: "name"}, Desc: true})
// db.Order(clause.OrderBy{Columns: []clause.OrderByColumn{
// {Column: clause.Column{Name: "name"}, Desc: true},
// {Column: clause.Column{Name: "age"}, Desc: true},
// }})
func (db *DB) Order(value interface{}) (tx *DB) {
tx = db.getInstance()
switch v := value.(type) {
case clause.OrderBy:
tx.Statement.AddClause(v)
case clause.OrderByColumn:
tx.Statement.AddClause(clause.OrderBy{
Columns: []clause.OrderByColumn{v},