Documentation ¶
Overview ¶
Package mongodb is an output adapter to store entities in MongoDB
Package mongodb is an output adapter to store entities in MongoDB ¶
Package mongodb is an output adapter to store entities in MongoDB ¶
Package mongodb is an output adapter to store entities in MongoDB ¶
Package mongodb is an output adapter to store entities in MongoDB ¶
Package mongodb is an output adapter to store entities in MongoDB
Index ¶
- Constants
- func NewMongoDBRepository(collection *mongo.Collection, cryptoKey []byte) *mongoDBRepository
- func NewMongoDBRepositoryWithHooks(collection *mongo.Collection, cryptoKey []byte, hooks *HookBuilder) *mongoDBRepository
- type DMO
- type EntityDMOMongoDB
- func (dmo *EntityDMOMongoDB) Created() int64
- func (dmo *EntityDMOMongoDB) Email() string
- func (dmo *EntityDMOMongoDB) HydrateFromEntity(ety *user.UserEntity) error
- func (dmo *EntityDMOMongoDB) Id() string
- func (dmo *EntityDMOMongoDB) Miles() int64
- func (dmo *EntityDMOMongoDB) Name() string
- func (dmo *EntityDMOMongoDB) Password() (string, error)
- func (dmo *EntityDMOMongoDB) Plan() string
- func (dmo *EntityDMOMongoDB) ToEntity() (*user.UserEntity, error)
- func (dmo *EntityDMOMongoDB) Updated() int64
- type HookBuilder
- type Hooks
- type IDeleteByHooks
- type IDeleteByIdHooks
- type IFetchByIdHooks
- type IQueryHooks
- type ISaveHooks
- type IUpdateHooks
- type NoopHooks
- func (o *NoopHooks) AfterDeleteBy(count int64, err error) error
- func (o *NoopHooks) AfterDeleteById(err error) error
- func (o *NoopHooks) AfterFetchById(dmo *EntityDMOMongoDB, err error) error
- func (o *NoopHooks) AfterQuery(err error) error
- func (o *NoopHooks) AfterSave(dmo *EntityDMOMongoDB, err error) error
- func (o *NoopHooks) AfterUpdate(dmo *EntityDMOMongoDB, err error) error
- func (o *NoopHooks) BeforeDeleteBy(field, val string) error
- func (o *NoopHooks) BeforeDeleteById(id string) error
- func (o *NoopHooks) BeforeFetchById(id string) error
- func (o *NoopHooks) BeforeQuery(q *tql.Query) error
- func (o *NoopHooks) BeforeSave(dmo *EntityDMOMongoDB) error
- func (o *NoopHooks) BeforeUpdate(dmo *EntityDMOMongoDB) error
Constants ¶
const (
// CollectionName the mongodb collection name where the entity objects will be stored
CollectionName = "users"
)
Variables ¶
This section is empty.
Functions ¶
func NewMongoDBRepository ¶
func NewMongoDBRepository(collection *mongo.Collection, cryptoKey []byte) *mongoDBRepository
NewMongoDBRepository repository constructor
func NewMongoDBRepositoryWithHooks ¶
func NewMongoDBRepositoryWithHooks(collection *mongo.Collection, cryptoKey []byte, hooks *HookBuilder) *mongoDBRepository
NewMongoDBRepositoryWithHooks repository constructor
Types ¶
type EntityDMOMongoDB ¶
type EntityDMOMongoDB struct { *user.EntityDMO `bson:"-"` Id_ string `bson:"_id"` Created_ int64 `bson:"created"` Updated_ int64 `bson:"updated"` Name_ string `bson:"name" ` Email_ string `bson:"email" ` Password_ string `bson:"password" torpedo.field:"encrypted"` Plan_ string `bson:"plan" ` Miles_ int64 `bson:"miles" ` DMO `bson:"inline"` }
EntityDMOMongoDB Data Mapper Object (DMO) to store entity into MongoDB
func NewEntityDMOMongoDB ¶
func NewEntityDMOMongoDB(key []byte) *EntityDMOMongoDB
NewEntityDMOMongoDB constructor function
params: - key []byte is the encryption key for the encrypted fields
func NewEntityDMOMongoDBFrom ¶
func NewEntityDMOMongoDBFrom(ety *user.UserEntity, key []byte) (*EntityDMOMongoDB, error)
NewEntityDMOMongoDBFrom DMO constructor function from a given user.UserEntity.
params: - ety: *user.UserEntity entity from the DMO will be created - key: []byte is the encryption key for the encrypted fields
func (*EntityDMOMongoDB) Created ¶
func (dmo *EntityDMOMongoDB) Created() int64
Created getter method
func (*EntityDMOMongoDB) HydrateFromEntity ¶
func (dmo *EntityDMOMongoDB) HydrateFromEntity(ety *user.UserEntity) error
HydrateFromEntity populates the DMO fields from the user.UserEntity
func (*EntityDMOMongoDB) Password ¶
func (dmo *EntityDMOMongoDB) Password() (string, error)
Password getter method
func (*EntityDMOMongoDB) ToEntity ¶
func (dmo *EntityDMOMongoDB) ToEntity() (*user.UserEntity, error)
ToEntity returns a user.UserEntity from the DMO object
func (*EntityDMOMongoDB) Updated ¶
func (dmo *EntityDMOMongoDB) Updated() int64
Updated getter method
type HookBuilder ¶
type HookBuilder struct {
// contains filtered or unexported fields
}
HookBuilder struct called from the mongodb repo object. If the user has no set the desired builder function, a noop is set by default
func NewHookBuilder ¶
func NewHookBuilder(hooks *Hooks) *HookBuilder
NewHookBuilder creates a hooks builder with a noop hook by default which can be overwritten by developers via hooks parameter
func (*HookBuilder) DeleteBy ¶
func (h *HookBuilder) DeleteBy() IDeleteByHooks
func (*HookBuilder) DeleteById ¶
func (h *HookBuilder) DeleteById() IDeleteByIdHooks
func (*HookBuilder) FetchById ¶
func (h *HookBuilder) FetchById() IFetchByIdHooks
func (*HookBuilder) Query ¶
func (h *HookBuilder) Query() IQueryHooks
func (*HookBuilder) Save ¶
func (h *HookBuilder) Save() ISaveHooks
func (*HookBuilder) Update ¶
func (h *HookBuilder) Update() IUpdateHooks
type Hooks ¶
type Hooks struct { Save func() ISaveHooks FetchById func() IFetchByIdHooks Update func() IUpdateHooks DeleteById func() IDeleteByIdHooks DeleteBy func() IDeleteByHooks Query func() IQueryHooks }
Hooks struct used as parameter to set the user builder hooks in the builder instance
type IDeleteByHooks ¶
type IDeleteByHooks interface { BeforeDeleteBy(field, val string) error AfterDeleteBy(count int64, err error) error }
IDeleteByHooks defines the before and after methods to be call at db delete by field operation
type IDeleteByIdHooks ¶
type IDeleteByIdHooks interface { BeforeDeleteById(id string) error AfterDeleteById(err error) error }
IDeleteByIdHooks defines the before and after methods to be call at db delete by id operation
type IFetchByIdHooks ¶
type IFetchByIdHooks interface { BeforeFetchById(id string) error AfterFetchById(dmo *EntityDMOMongoDB, err error) error }
IFetchByIdHooks defines the before and after methods to be call at db fetch by id operation
type IQueryHooks ¶
IQueryHooks defines the before and after methods to be call at db query operation
type ISaveHooks ¶
type ISaveHooks interface { BeforeSave(dmo *EntityDMOMongoDB) error AfterSave(dmo *EntityDMOMongoDB, err error) error }
ISaveHooks interface that defines the before and after methods to be call at db save operation
type IUpdateHooks ¶
type IUpdateHooks interface { BeforeUpdate(dmo *EntityDMOMongoDB) error AfterUpdate(dmo *EntityDMOMongoDB, err error) error }
IUpdateHooks interface that defines the before and after methods to be call at db update operation
type NoopHooks ¶
type NoopHooks struct{}
NoopHooks implement the hook interfaces to call when a dev doesn't set it.
func (*NoopHooks) AfterDeleteById ¶
func (*NoopHooks) AfterFetchById ¶
func (o *NoopHooks) AfterFetchById(dmo *EntityDMOMongoDB, err error) error
func (*NoopHooks) AfterQuery ¶
func (*NoopHooks) AfterUpdate ¶
func (o *NoopHooks) AfterUpdate(dmo *EntityDMOMongoDB, err error) error
func (*NoopHooks) BeforeDeleteBy ¶
func (*NoopHooks) BeforeDeleteById ¶
func (*NoopHooks) BeforeFetchById ¶
func (*NoopHooks) BeforeSave ¶
func (o *NoopHooks) BeforeSave(dmo *EntityDMOMongoDB) error
func (*NoopHooks) BeforeUpdate ¶
func (o *NoopHooks) BeforeUpdate(dmo *EntityDMOMongoDB) error