mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-12-05 10:28:59 +08:00
49 lines
1.5 KiB
Go
49 lines
1.5 KiB
Go
package repo
|
|
|
|
import "github.com/1Panel-dev/1Panel/backend/app/model"
|
|
|
|
type IAcmeAccountRepo interface {
|
|
Page(page, size int, opts ...DBOption) (int64, []model.WebsiteAcmeAccount, error)
|
|
GetFirst(opts ...DBOption) (model.WebsiteAcmeAccount, error)
|
|
Create(account model.WebsiteAcmeAccount) error
|
|
Save(account model.WebsiteAcmeAccount) error
|
|
DeleteBy(opts ...DBOption) error
|
|
}
|
|
|
|
func NewIAcmeAccountRepo() IAcmeAccountRepo {
|
|
return &WebsiteAcmeAccountRepo{}
|
|
}
|
|
|
|
type WebsiteAcmeAccountRepo struct {
|
|
}
|
|
|
|
func (w *WebsiteAcmeAccountRepo) Page(page, size int, opts ...DBOption) (int64, []model.WebsiteAcmeAccount, error) {
|
|
var accounts []model.WebsiteAcmeAccount
|
|
db := getDb(opts...).Model(&model.WebsiteAcmeAccount{})
|
|
count := int64(0)
|
|
db = db.Count(&count)
|
|
err := db.Debug().Limit(size).Offset(size * (page - 1)).Find(&accounts).Error
|
|
return count, accounts, err
|
|
}
|
|
|
|
func (w *WebsiteAcmeAccountRepo) GetFirst(opts ...DBOption) (model.WebsiteAcmeAccount, error) {
|
|
var account model.WebsiteAcmeAccount
|
|
db := getDb(opts...).Model(&model.WebsiteAcmeAccount{})
|
|
if err := db.First(&account).Error; err != nil {
|
|
return account, err
|
|
}
|
|
return account, nil
|
|
}
|
|
|
|
func (w *WebsiteAcmeAccountRepo) Create(account model.WebsiteAcmeAccount) error {
|
|
return getDb().Create(&account).Error
|
|
}
|
|
|
|
func (w *WebsiteAcmeAccountRepo) Save(account model.WebsiteAcmeAccount) error {
|
|
return getDb().Save(&account).Error
|
|
}
|
|
|
|
func (w *WebsiteAcmeAccountRepo) DeleteBy(opts ...DBOption) error {
|
|
return getDb(opts...).Debug().Delete(&model.WebsiteAcmeAccount{}).Error
|
|
}
|