mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-08 02:20:24 +08:00
阶段性提交
This commit is contained in:
65
internal/db/models/http_cache_policy_dao.go
Normal file
65
internal/db/models/http_cache_policy_dao.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
)
|
||||
|
||||
const (
|
||||
HTTPCachePolicyStateEnabled = 1 // 已启用
|
||||
HTTPCachePolicyStateDisabled = 0 // 已禁用
|
||||
)
|
||||
|
||||
type HTTPCachePolicyDAO dbs.DAO
|
||||
|
||||
func NewHTTPCachePolicyDAO() *HTTPCachePolicyDAO {
|
||||
return dbs.NewDAO(&HTTPCachePolicyDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgeHTTPCachePolicies",
|
||||
Model: new(HTTPCachePolicy),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*HTTPCachePolicyDAO)
|
||||
}
|
||||
|
||||
var SharedHTTPCachePolicyDAO = NewHTTPCachePolicyDAO()
|
||||
|
||||
// 启用条目
|
||||
func (this *HTTPCachePolicyDAO) EnableHTTPCachePolicy(id int64) error {
|
||||
_, err := this.Query().
|
||||
Pk(id).
|
||||
Set("state", HTTPCachePolicyStateEnabled).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// 禁用条目
|
||||
func (this *HTTPCachePolicyDAO) DisableHTTPCachePolicy(id int64) error {
|
||||
_, err := this.Query().
|
||||
Pk(id).
|
||||
Set("state", HTTPCachePolicyStateDisabled).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// 查找启用中的条目
|
||||
func (this *HTTPCachePolicyDAO) FindEnabledHTTPCachePolicy(id int64) (*HTTPCachePolicy, error) {
|
||||
result, err := this.Query().
|
||||
Pk(id).
|
||||
Attr("state", HTTPCachePolicyStateEnabled).
|
||||
Find()
|
||||
if result == nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.(*HTTPCachePolicy), err
|
||||
}
|
||||
|
||||
// 根据主键查找名称
|
||||
func (this *HTTPCachePolicyDAO) FindHTTPCachePolicyName(id int64) (string, error) {
|
||||
return this.Query().
|
||||
Pk(id).
|
||||
Result("name").
|
||||
FindStringCol("")
|
||||
}
|
||||
Reference in New Issue
Block a user