fix: 修复opt_lock引入第三方包的问题,无需。

main v1.0.5
NoahLan 2 years ago
parent 2eb42c0c88
commit 3e614c38e4

@ -7,7 +7,6 @@ import (
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/mixin"
"fmt"
"github.com/casbin/ent-adapter/ent/hook"
)
// OptimisticLockMixin implements the ent.Mixin for sharing
@ -34,9 +33,9 @@ func WithVersion(parent context.Context, version int64) context.Context {
// Hooks of the OptimisticLockMixin.
func (d OptimisticLockMixin) Hooks() []ent.Hook {
return []ent.Hook{
hook.On(
func(next ent.Mutator) ent.Mutator {
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) {
func(next ent.Mutator) ent.Mutator {
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if m.Op().Is(ent.OpUpdate | ent.OpUpdateOne) {
mx, ok := m.(interface {
AddVersion(i int64)
WhereP(...func(*sql.Selector))
@ -52,10 +51,10 @@ func (d OptimisticLockMixin) Hooks() []ent.Hook {
// set version=version+1
mx.AddVersion(1)
return next.Mutate(ctx, m)
})
},
ent.OpUpdate|ent.OpUpdateOne,
),
}
return next.Mutate(ctx, m)
})
},
}
}

Loading…
Cancel
Save