/
website_dns_account.go
60 lines (50 loc) · 1.83 KB
/
website_dns_account.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package repo
import (
"github.com/1Panel-dev/1Panel/backend/app/model"
)
type WebsiteDnsAccountRepo struct {
}
type IWebsiteDnsAccountRepo interface {
Page(page, size int, opts ...DBOption) (int64, []model.WebsiteDnsAccount, error)
GetFirst(opts ...DBOption) (*model.WebsiteDnsAccount, error)
List(opts ...DBOption) ([]model.WebsiteDnsAccount, error)
Create(account model.WebsiteDnsAccount) error
Save(account model.WebsiteDnsAccount) error
DeleteBy(opts ...DBOption) error
}
func NewIWebsiteDnsAccountRepo() IWebsiteDnsAccountRepo {
return &WebsiteDnsAccountRepo{}
}
func (w WebsiteDnsAccountRepo) Page(page, size int, opts ...DBOption) (int64, []model.WebsiteDnsAccount, error) {
var accounts []model.WebsiteDnsAccount
db := getDb(opts...).Model(&model.WebsiteDnsAccount{})
count := int64(0)
db = db.Count(&count)
err := db.Limit(size).Offset(size * (page - 1)).Find(&accounts).Error
return count, accounts, err
}
func (w WebsiteDnsAccountRepo) GetFirst(opts ...DBOption) (*model.WebsiteDnsAccount, error) {
var account model.WebsiteDnsAccount
db := getDb(opts...).Model(&model.WebsiteDnsAccount{})
if err := db.First(&account).Error; err != nil {
return nil, err
}
return &account, nil
}
func (w WebsiteDnsAccountRepo) List(opts ...DBOption) ([]model.WebsiteDnsAccount, error) {
var accounts []model.WebsiteDnsAccount
db := getDb(opts...).Model(&model.WebsiteDnsAccount{})
if err := db.Find(&accounts).Error; err != nil {
return nil, err
}
return accounts, nil
}
func (w WebsiteDnsAccountRepo) Create(account model.WebsiteDnsAccount) error {
return getDb().Create(&account).Error
}
func (w WebsiteDnsAccountRepo) Save(account model.WebsiteDnsAccount) error {
return getDb().Save(&account).Error
}
func (w WebsiteDnsAccountRepo) DeleteBy(opts ...DBOption) error {
return getDb(opts...).Delete(&model.WebsiteDnsAccount{}).Error
}