package db import ( "gorm.io/gorm" ) type DeleteBuilder[T any] struct { db *gorm.DB expr *Expr } func NewDeleteBuilder[T any](db *gorm.DB) *DeleteBuilder[T] { return &DeleteBuilder[T]{db: db, expr: &Expr{}} } func (d *DeleteBuilder[T]) Eq(col string, val any) *DeleteBuilder[T] { d.expr.Eq(col, val) return d } func (d *DeleteBuilder[T]) Neq(col string, val any) *DeleteBuilder[T] { d.expr.Neq(col, val) return d } func (d *DeleteBuilder[T]) Lt(col string, val any) *DeleteBuilder[T] { d.expr.Lt(col, val) return d } func (d *DeleteBuilder[T]) Lte(col string, val any) *DeleteBuilder[T] { d.expr.Lte(col, val) return d } func (d *DeleteBuilder[T]) Gt(col string, val any) *DeleteBuilder[T] { d.expr.Gt(col, val) return d } func (d *DeleteBuilder[T]) Gte(col string, val any) *DeleteBuilder[T] { d.expr.Gte(col, val) return d } func (d *DeleteBuilder[T]) Between(col string, less, more any) *DeleteBuilder[T] { d.expr.Between(col, less, more) return d } func (d *DeleteBuilder[T]) NotBetween(col string, less, more any) *DeleteBuilder[T] { d.expr.NotBetween(col, less, more) return d } func (d *DeleteBuilder[T]) IsNull(col string) *DeleteBuilder[T] { d.expr.IsNull(col) return d } func (d *DeleteBuilder[T]) NotNull(col string) *DeleteBuilder[T] { d.expr.NotNull(col) return d } func (d *DeleteBuilder[T]) Like(col, tpl string) *DeleteBuilder[T] { d.expr.Like(col, tpl) return d } func (d *DeleteBuilder[T]) NotLike(col, tpl string) *DeleteBuilder[T] { d.expr.NotLike(col, tpl) return d } func (d *DeleteBuilder[T]) In(col string, values ...any) *DeleteBuilder[T] { d.expr.In(col, values...) return d } func (d *DeleteBuilder[T]) NotIn(col string, values ...any) *DeleteBuilder[T] { d.expr.NotIn(col, values...) return d } func (d *DeleteBuilder[T]) When(condition bool, then func(ex *Expr), elses ...func(ex *Expr)) *DeleteBuilder[T] { d.expr.When(condition, then, elses...) return d } func (d *DeleteBuilder[T]) Or(or func(ex *Expr)) *DeleteBuilder[T] { d.expr.Or(or) return d } func (d *DeleteBuilder[T]) And(and func(ex *Expr)) *DeleteBuilder[T] { d.expr.And(and) return d } func (d *DeleteBuilder[T]) Not(not func(ex *Expr)) *DeleteBuilder[T] { d.expr.Not(not) return d } func (d *DeleteBuilder[T]) Commit() (int64, error) { var t T res := d.db.Scopes(d.expr.Scopes).Delete(&t) return res.RowsAffected, res.Error }