mongodb

package
v0.0.0-...-f52bcce Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2024 License: MIT Imports: 10 Imported by: 0

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

View Source
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 DMO

type DMO struct {
	*user.EntityDMO `bson:"-"` // Do not remove it. This will let you add custom encrypted fields and more.

}

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) Email

func (dmo *EntityDMOMongoDB) Email() string

Email getter method

func (*EntityDMOMongoDB) HydrateFromEntity

func (dmo *EntityDMOMongoDB) HydrateFromEntity(ety *user.UserEntity) error

HydrateFromEntity populates the DMO fields from the user.UserEntity

func (*EntityDMOMongoDB) Id

func (dmo *EntityDMOMongoDB) Id() string

Id getter method

func (*EntityDMOMongoDB) Miles

func (dmo *EntityDMOMongoDB) Miles() int64

Miles getter method

func (*EntityDMOMongoDB) Name

func (dmo *EntityDMOMongoDB) Name() string

Name getter method

func (*EntityDMOMongoDB) Password

func (dmo *EntityDMOMongoDB) Password() (string, error)

Password getter method

func (*EntityDMOMongoDB) Plan

func (dmo *EntityDMOMongoDB) Plan() string

Plan 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

type IQueryHooks interface {
	BeforeQuery(q *tql.Query) error
	AfterQuery(err error) error
}

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) AfterDeleteBy

func (o *NoopHooks) AfterDeleteBy(count int64, err error) error

func (*NoopHooks) AfterDeleteById

func (o *NoopHooks) AfterDeleteById(err error) error

func (*NoopHooks) AfterFetchById

func (o *NoopHooks) AfterFetchById(dmo *EntityDMOMongoDB, err error) error

func (*NoopHooks) AfterQuery

func (o *NoopHooks) AfterQuery(err error) error

func (*NoopHooks) AfterSave

func (o *NoopHooks) AfterSave(dmo *EntityDMOMongoDB, err error) error

func (*NoopHooks) AfterUpdate

func (o *NoopHooks) AfterUpdate(dmo *EntityDMOMongoDB, err error) error

func (*NoopHooks) BeforeDeleteBy

func (o *NoopHooks) BeforeDeleteBy(field, val string) error

func (*NoopHooks) BeforeDeleteById

func (o *NoopHooks) BeforeDeleteById(id string) error

func (*NoopHooks) BeforeFetchById

func (o *NoopHooks) BeforeFetchById(id string) error

func (*NoopHooks) BeforeQuery

func (o *NoopHooks) BeforeQuery(q *tql.Query) error

func (*NoopHooks) BeforeSave

func (o *NoopHooks) BeforeSave(dmo *EntityDMOMongoDB) error

func (*NoopHooks) BeforeUpdate

func (o *NoopHooks) BeforeUpdate(dmo *EntityDMOMongoDB) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL