warehouse/database/controller.go
2024-11-13 21:16:22 +01:00

31 lines
818 B
Go

package database
import (
"git.schreifuchs.ch/schreifuchs/warehouse/api"
"git.schreifuchs.ch/schreifuchs/warehouse/model"
)
func (db *DB) InsertBucket(bucket *model.Bucket) error {
return db.conn.Create(bucket).Error
}
func (db *DB) FindApiBuckets(limit, offset int) (buckets []api.Bucket, err error) {
buckets = make([]api.Bucket, 0)
err = db.conn.Model(&model.Bucket{}).Limit(limit).Offset(offset).Find(&buckets).Error
return
}
func (db *DB) FindBucketIdByName(name string) (id uint, err error) {
b := &model.Bucket{}
err = db.conn.Select("id").First(b).Error
return b.ID, err
}
func (db *DB) DeleteBucket(id uint) error {
return db.conn.Delete(&model.Bucket{}, id).Error
}
func (db *DB) DeleteBucketByName(name string) error {
return db.conn.Delete(&model.Bucket{}).Where("name = ?", name).Error
}