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.
19 lines
336 B
19 lines
336 B
1 year ago
|
package db
|
||
|
|
||
|
import "gorm.io/gorm"
|
||
|
|
||
|
type DeleteBuilder[T any] struct {
|
||
|
Expr
|
||
|
db *gorm.DB
|
||
|
}
|
||
|
|
||
|
func NewDeleteBuilder[T any](db *gorm.DB) *DeleteBuilder[T] {
|
||
|
return &DeleteBuilder[T]{Expr{}, db}
|
||
|
}
|
||
|
|
||
|
func (b *DeleteBuilder[T]) Commit() (int64, error) {
|
||
|
var t T
|
||
|
res := b.db.Scopes(b.Scopes).Delete(&t)
|
||
|
return res.RowsAffected, res.Error
|
||
|
}
|