mirror of
https://github.com/mainnika/mongox-go-driver.git
synced 2026-05-22 15:53:36 +00:00
Let the protection key restate itself
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package protection
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
@@ -9,3 +11,9 @@ type Key struct {
|
||||
X primitive.ObjectID `bson:"_x" json:"_x" index:",hashed"`
|
||||
V int64 `bson:"_v" json:"_v"`
|
||||
}
|
||||
|
||||
// Restate creates a new protection key
|
||||
func (k *Key) Restate() {
|
||||
k.X = primitive.NewObjectID()
|
||||
k.V = time.Now().Unix()
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package database
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/modern-go/reflect2"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
@@ -33,8 +32,7 @@ func (d *Database) DeleteOne(target interface{}, filters ...interface{}) (err er
|
||||
|
||||
if protected != nil {
|
||||
query.Push(composed, protected)
|
||||
protected.X = primitive.NewObjectID()
|
||||
protected.V = time.Now().Unix()
|
||||
protected.Restate()
|
||||
}
|
||||
|
||||
defer func() {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
|
||||
@@ -31,8 +29,7 @@ func (d *Database) SaveOne(source interface{}, filters ...interface{}) (err erro
|
||||
|
||||
if protected != nil {
|
||||
query.Push(composed, protected)
|
||||
protected.X = primitive.NewObjectID()
|
||||
protected.V = time.Now().Unix()
|
||||
protected.Restate()
|
||||
}
|
||||
|
||||
defer func() {
|
||||
|
||||
@@ -38,6 +38,7 @@ func (d *Database) UpdateOne(target interface{}, filters ...interface{}) (err er
|
||||
// "_v": time.Now().Unix(),
|
||||
// },
|
||||
//})
|
||||
protected.Restate()
|
||||
}
|
||||
|
||||
defer func() {
|
||||
|
||||
Reference in New Issue
Block a user