精简后的项目:仅保留 api/ui 源码、文档、构建依赖
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
func FormatSQL(tx *gorm.DB, order *Ordering, paginate *Pagination) *gorm.DB {
|
||||
|
||||
if paginate != nil {
|
||||
if paginate.Limit != nil {
|
||||
tx.Limit(*paginate.Limit)
|
||||
}
|
||||
|
||||
if paginate.Offset != nil {
|
||||
tx.Offset(*paginate.Offset)
|
||||
}
|
||||
}
|
||||
|
||||
if order != nil && order.OrderBy != nil {
|
||||
desc := false
|
||||
if order.OrderDirection != nil && order.OrderDirection.IsValid() {
|
||||
if *order.OrderDirection == OrderDirectionDesc {
|
||||
desc = true
|
||||
}
|
||||
}
|
||||
|
||||
tx.Order(clause.OrderByColumn{
|
||||
Column: clause.Column{
|
||||
Name: *order.OrderBy,
|
||||
},
|
||||
Desc: desc,
|
||||
})
|
||||
}
|
||||
|
||||
return tx
|
||||
}
|
||||
|
||||
// MD5Hash hashes value to a 32 length digest, the result is the same as the MYSQL function md5()
|
||||
func MD5Hash(value string) string {
|
||||
hash := md5.Sum([]byte(value))
|
||||
return hex.EncodeToString(hash[:])
|
||||
}
|
||||
Reference in New Issue
Block a user