1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-20 16:59:17 +08:00
1Panel/backend/app/repo/app_container.go

38 lines
951 B
Go
Raw Normal View History

package repo
import (
"context"
"github.com/1Panel-dev/1Panel/app/model"
"github.com/1Panel-dev/1Panel/global"
"gorm.io/gorm"
)
type AppContainerRepo struct {
}
2022-10-07 15:49:39 +08:00
func (a AppContainerRepo) WithAppId(appId uint) DBOption {
return func(db *gorm.DB) *gorm.DB {
return db.Where("app_id = ?", appId)
}
}
func (a AppContainerRepo) GetBy(opts ...DBOption) ([]model.AppContainer, error) {
db := global.DB.Model(&model.AppContainer{})
var appContainers []model.AppContainer
for _, opt := range opts {
db = opt(db)
}
err := db.Find(&appContainers).Error
return appContainers, err
}
func (a AppContainerRepo) Create(container *model.AppContainer) error {
db := global.DB.Model(&model.AppContainer{})
return db.Create(&container).Error
}
func (a AppContainerRepo) BatchCreate(ctx context.Context, containers []*model.AppContainer) error {
db := ctx.Value("db").(*gorm.DB)
return db.Model(&model.AppContainer{}).Create(&containers).Error
}