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