ObjectId base might be empty

v2
Nikita Tokarchuk 6 years ago
parent e8cd680cde
commit b4d4fc666e
  1. 5
      mongox/base/objectid.go
  2. 9
      mongox/common.go

@ -1,12 +1,15 @@
package base package base
import ( import (
"github.com/mainnika/mongox-go-driver/mongox"
"github.com/mongodb/mongo-go-driver/bson/primitive" "github.com/mongodb/mongo-go-driver/bson/primitive"
) )
var _ mongox.BaseObjectID = &ObjectID{}
// ObjectID is a structure with objectId as an _id field // ObjectID is a structure with objectId as an _id field
type ObjectID struct { type ObjectID struct {
ID primitive.ObjectID `bson:"_id" json:"_id"` ID primitive.ObjectID `bson:"_id,omitempty" json:"_id,omitempty"`
} }
// GetID returns an _id // GetID returns an _id

@ -1,5 +1,9 @@
package mongox package mongox
import (
"github.com/mongodb/mongo-go-driver/bson/primitive"
)
type Saver interface { type Saver interface {
Save(db *Database) error Save(db *Database) error
} }
@ -11,3 +15,8 @@ type Deleter interface {
type Loader interface { type Loader interface {
Load(db *Database, filters ...interface{}) error Load(db *Database, filters ...interface{}) error
} }
type BaseObjectID interface {
GetID() primitive.ObjectID
SetID(id primitive.ObjectID)
}

Loading…
Cancel
Save