zhangzengfei
2023-09-04 e8e536d1cb52d2126c8c7ce2ba1c7a76f7208678
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package models
 
type AutoBackupConf struct {
    Enable             bool         `json:"enable"`      //自动备份开关
    Dir             string         `json:"dir"`         //备份目录
    Period             int         `json:"period"`        //备份间隔
    SaveDays         int         `json:"saveDays"`    //保存天数
}
 
func (AutoBackupConf) TableName() string {
    return "auto_backup"
}
 
func (a *AutoBackupConf) Insert() bool {
    result := db.Table(a.TableName()).Create(&a)
    if result.Error !=nil {
        return false
    }
    return result.RowsAffected>0
}
 
func (a *AutoBackupConf) Update() bool {
    db.Table(a.TableName()).Delete(&a)
    result := db.Table(a.TableName()).Create(&a)
    if result.Error !=nil {
        return false
    }
    return result.RowsAffected>0
}
 
func (a *AutoBackupConf) Select() (int64, error){
    result := db.Table(a.TableName()).First(&a)
    if result.Error != nil || result.RowsAffected == 0 {
        return 0, result.Error
    }
    return result.RowsAffected, nil
}