mgmadapter

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2022 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmptyID

func EmptyID() hexa.ID

EmptyID returns empty instance of the id.

func HealthPing

func HealthPing(cli *mongo.Client) hexa.Ping

func ID

func ID(id any) hexa.ID

ID function get an id and returns IDD

func NewComposedMonitor

func NewComposedMonitor(monitors ...*event.CommandMonitor) *event.CommandMonitor

func NewLogMonitor

func NewLogMonitor(l hlog.Logger) *event.CommandMonitor

Types

type Entity

type Entity struct {
	IDField `bson:",inline"`
}

Entity struct contain model's default fields.

type IDField

type IDField struct {
	ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
}

IDField struct contain model's ID field. This struct implements the mgm.Model and mgmrel.Syncing interfaces.

func (*IDField) GetID

func (f *IDField) GetID() any

GetID method return model's id

func (*IDField) PrepareID

func (f *IDField) PrepareID(id any) (objID any, err error)

PrepareID method prepare id value to using it as id in filtering,... e.g convert hex-string id value to bson.ObjectId

func (*IDField) SetID

func (f *IDField) SetID(id any)

SetID set id value of model's id field.

func (*IDField) Syncing

func (f *IDField) Syncing() error

Syncing sets the ID if it's zero(empty ID). This is mgm-relation library hook. @deprecated

type Store

type Store struct {
}

func (Store) CreateIndexIfNotExist

func (r Store) CreateIndexIfNotExist(coll *mgm.Collection, name string, keys ...any) error

func (*Store) CreateIndexWithOptionsIfNotExist

func (r *Store) CreateIndexWithOptionsIfNotExist(coll *mgm.Collection, o *options.IndexOptions, fields ...any) error

CreateIndexWithOptionsIfNotExist creates index if it doesn't exist. fields value could be either string or bson.E. One exception is if the first field value's type is bson.D, we will use it and ignore all other fields values. otherwise if you send another type as field it will panic.

func (Store) CreateUniqueIndexIfNotExist

func (r Store) CreateUniqueIndexIfNotExist(coll *mgm.Collection, name string, keys ...any) error

func (Store) ReplaceErr

func (r Store) ReplaceErr(err error, notfoundErr error) error

type TimeTouchable

type TimeTouchable struct {
	CreatedAt time.Time `json:"created_at" bson:"created_at"`
	UpdatedAt time.Time `json:"updated_at" bson:"updated_at"`
}

func (*TimeTouchable) Touch

func (t *TimeTouchable) Touch()

func (*TimeTouchable) TouchAt

func (t *TimeTouchable) TouchAt(at time.Time)

TouchAt is idempotent, so you can call it multiple time.

type Touchable

type Touchable struct {
	VersionTouchable `bson:",inline"`
	TimeTouchable    `bson:",inline"`
}

func (*Touchable) Touch

func (t *Touchable) Touch()

Touch is idempotent.

func (*Touchable) TouchAt

func (t *Touchable) TouchAt(at time.Time)

TouchAt is idempotent.

type TouchableEntity

type TouchableEntity struct {
	IDField   `bson:",inline"`
	Touchable `bson:",inline"`
}

TouchableEntity struct is the entity base struct with touch feature to increase its version on each change or set date fields on each update.

type VersionTouchable

type VersionTouchable struct {
	Version int64 `json:"v" bson:"v"`
	// contains filtered or unexported fields
}

func (*VersionTouchable) Touch

func (t *VersionTouchable) Touch()

Touch is idempotent, so you can call it multiple times.

Jump to

Keyboard shortcuts

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