mirror of https://github.com/1Panel-dev/1Panel
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.1 KiB
43 lines
1.1 KiB
2 years ago
|
package repo
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"github.com/1Panel-dev/1Panel/backend/app/model"
|
||
|
)
|
||
|
|
||
|
type RuntimeRepo struct {
|
||
|
}
|
||
|
|
||
|
type IRuntimeRepo interface {
|
||
|
Page(page, size int, opts ...DBOption) (int64, []model.Runtime, error)
|
||
|
Create(ctx context.Context, runtime *model.Runtime) error
|
||
|
Save(runtime *model.Runtime) error
|
||
|
DeleteBy(opts ...DBOption) error
|
||
|
}
|
||
|
|
||
|
func NewIRunTimeRepo() IRuntimeRepo {
|
||
|
return &RuntimeRepo{}
|
||
|
}
|
||
|
|
||
|
func (r *RuntimeRepo) Page(page, size int, opts ...DBOption) (int64, []model.Runtime, error) {
|
||
|
var runtimes []model.Runtime
|
||
|
db := getDb(opts...).Model(&model.Runtime{})
|
||
|
count := int64(0)
|
||
|
db = db.Count(&count)
|
||
|
err := db.Limit(size).Offset(size * (page - 1)).Find(&runtimes).Error
|
||
|
return count, runtimes, err
|
||
|
}
|
||
|
|
||
|
func (r *RuntimeRepo) Create(ctx context.Context, runtime *model.Runtime) error {
|
||
|
db := getTx(ctx).Model(&model.Runtime{})
|
||
|
return db.Create(&runtime).Error
|
||
|
}
|
||
|
|
||
|
func (r *RuntimeRepo) Save(runtime *model.Runtime) error {
|
||
|
return getDb().Save(&runtime).Error
|
||
|
}
|
||
|
|
||
|
func (r *RuntimeRepo) DeleteBy(opts ...DBOption) error {
|
||
|
return getDb(opts...).Delete(&model.Runtime{}).Error
|
||
|
}
|