From f65ef3e7d09ababbc1f57e552496c3adc0a81e5b Mon Sep 17 00:00:00 2001 From: hupeh Date: Mon, 2 Jan 2023 12:00:17 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20:bulb:=20=E6=B3=A8=E9=87=8A=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E6=A8=A1=E5=9E=8B=E5=92=8C=E4=BD=9C=E7=94=A8?= =?UTF-8?q?=E5=9F=9F=E7=BC=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/db.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/db.go b/app/db.go index 22102db..e23f2e1 100644 --- a/app/db.go +++ b/app/db.go @@ -7,6 +7,7 @@ import ( "strings" ) +// DB 用户数据操作 var DB *gorm.DB func ConfigGormDB() { @@ -20,6 +21,7 @@ func ConfigGormDB() { } } +// User 用户 type User struct { gorm.Model Name string `json:"name"` // 用户名称 @@ -42,6 +44,7 @@ type Price struct { Price float32 `json:"price"` // 商品价格 } +// Paginate 分页查询作用域 func Paginate(r *Request) func(db *gorm.DB) *gorm.DB { return func(db *gorm.DB) *gorm.DB { page := r.Int("page", 1, func(p int) int { @@ -55,6 +58,7 @@ func Paginate(r *Request) func(db *gorm.DB) *gorm.DB { } } +// Search 搜索作用域 func Search(r *Request, key, query string) func(db *gorm.DB) *gorm.DB { return func(db *gorm.DB) *gorm.DB { if keyword, ok := r.Get(key); ok { @@ -65,6 +69,7 @@ func Search(r *Request, key, query string) func(db *gorm.DB) *gorm.DB { } } +// TimeRange 时间范围作用域 func TimeRange(r *Request, column string) func(db *gorm.DB) *gorm.DB { return func(db *gorm.DB) *gorm.DB { var queries []string