26 lines
686 B
Go
26 lines
686 B
Go
package book
|
|
|
|
import (
|
|
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
|
commonReq "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func paginate(info commonReq.PageInfo) func(db *gorm.DB) *gorm.DB { return (&info).Paginate() }
|
|
|
|
func deleteByIDs[T any](ids []int) error {
|
|
return global.GVA_DB.Where("id in ?", ids).Delete(new(T)).Error
|
|
}
|
|
|
|
func createWithExplicitIsEnabled[T any](item *T, isEnabled bool) error {
|
|
return global.GVA_DB.Transaction(func(tx *gorm.DB) error {
|
|
if err := tx.Create(item).Error; err != nil {
|
|
return err
|
|
}
|
|
if isEnabled {
|
|
return nil
|
|
}
|
|
return tx.Model(item).Update("is_enabled", false).Error
|
|
})
|
|
}
|