mongo

package
v0.0.0-...-0948bf3 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEvent

func NewEvent[I repo.ID]() repo.Event[I]

func NewRepoOptions

func NewRepoOptions[I repo.ID, A dgo.AggBase, D any]() *repoOptions[I, A, D]

NewRepoOptions[I repo.ID,A dgo.AggBase,D any] new options struct

func NewVid

func NewVid[I repo.ID](id I, version uint64) repo.Vid[I]

func PrintRepoOptions

func PrintRepoOptions(packageName string)

func ReplaceError

func ReplaceError(err error) error

Types

type Aggregate

type Aggregate[I repo.ID, D any] interface {
	GetID() I
	SetID(I)
	Content[D]
	GetContent() Content[D]
}

func NewAggregate

func NewAggregate[I dr.ID, D any]() Aggregate[I, D]

type Content

type Content[D any] interface {
	GetCreatedAt() time.Time
	GetUpdatedAt() time.Time
	GetVersion() uint64
	GetData() D
	SetCreatedAt(time.Time)
	SetUpdatedAt(time.Time)
	SetVersion(uint64)
	SetData(D)
}

type DefaultContent

type DefaultContent[D any] struct {
	CreatedAt Time   `bson:"createdAt"`
	UpdatedAt Time   `bson:"updatedAt"`
	Version   uint64 `bson:"version"`
	Data      D      `bson:",inline"`
}

func (*DefaultContent[D]) GetCreatedAt

func (c *DefaultContent[D]) GetCreatedAt() time.Time

func (*DefaultContent[D]) GetData

func (c *DefaultContent[D]) GetData() D

func (*DefaultContent[D]) GetUpdatedAt

func (c *DefaultContent[D]) GetUpdatedAt() time.Time

func (*DefaultContent[D]) GetVersion

func (c *DefaultContent[D]) GetVersion() uint64

func (*DefaultContent[D]) SetCreatedAt

func (c *DefaultContent[D]) SetCreatedAt(t time.Time)

func (*DefaultContent[D]) SetData

func (c *DefaultContent[D]) SetData(d D)

func (*DefaultContent[D]) SetUpdatedAt

func (c *DefaultContent[D]) SetUpdatedAt(t time.Time)

func (*DefaultContent[D]) SetVersion

func (c *DefaultContent[D]) SetVersion(version uint64)

type Repo

type Repo[I repo.ID, A dgo.AggBase, D any] struct {
	// contains filtered or unexported fields
}

func NewDefaultRepo

func NewDefaultRepo[I repo.ID, A dgo.AggBase, D any](
	db *mg.Database,
	aggrName string,
	convert func(context.Context, A) (D, error),
	reverse func(context.Context, dgo.AggBase, D) (A, error),
	newData func() D,
	parseID repo.ParseID[I],
	_opts ...RepoOption[I, A, D],
) *Repo[I, A, D]

func NewRepo

func NewRepo[I repo.ID, A dgo.AggBase, D any](db *mg.Database, agg, event *mg.Collection, convert func(context.Context, A) (D, error), reverse func(context.Context, dgo.AggBase, D) (A, error), newData func() D, parseID repo.ParseID[I], _opts ...RepoOption[I, A, D]) *Repo[I, A, D]

NewRepo constructor

func (*Repo[I, A, D]) Agg

func (r *Repo[I, A, D]) Agg() *mg.Collection

func (*Repo[I, A, D]) DA2PA

func (r *Repo[I, A, D]) DA2PA(ctx context.Context, da A) (Aggregate[I, D], error)

func (*Repo[I, A, D]) DB

func (r *Repo[I, A, D]) DB() *mg.Database

func (*Repo[I, A, D]) Delete

func (r *Repo[I, A, D]) Delete(ctx context.Context, a A) error

func (*Repo[I, A, D]) Event

func (r *Repo[I, A, D]) Event() *mg.Collection

func (*Repo[I, A, D]) FindDA

func (r *Repo[I, A, D]) FindDA(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) (d A, err error)

func (*Repo[I, A, D]) FindDAs

func (r *Repo[I, A, D]) FindDAs(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (das []A, err error)

func (*Repo[I, A, D]) FindPA

func (r *Repo[I, A, D]) FindPA(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) (Aggregate[I, D], error)

func (*Repo[I, A, D]) FindPAs

func (r *Repo[I, A, D]) FindPAs(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (pas []Aggregate[I, D], err error)

func (*Repo[I, A, D]) Get

func (r *Repo[I, A, D]) Get(ctx context.Context, id dgo.ID) (a A, err error)

func (*Repo[I, A, D]) List

func (r *Repo[I, A, D]) List(ctx context.Context, ids ...dgo.ID) (as []A, err error)

func (*Repo[I, A, D]) PA2DA

func (r *Repo[I, A, D]) PA2DA(ctx context.Context, pa Aggregate[I, D]) (A, error)

func (*Repo[I, A, D]) ParseID

func (r *Repo[I, A, D]) ParseID(id dgo.ID) (I, error)

func (*Repo[I, A, D]) Save

func (r *Repo[I, A, D]) Save(ctx context.Context, a A) error

func (*Repo[I, A, D]) SaveEvents

func (r *Repo[I, A, D]) SaveEvents(ctx context.Context, unsaved dgo.Events) error

func (*Repo[I, A, D]) SetOptions

func (_r *Repo[I, A, D]) SetOptions(_opts ...RepoOption[I, A, D]) *Repo[I, A, D]

func (*Repo[I, A, D]) Transaction

func (r *Repo[I, A, D]) Transaction(ctx context.Context, fn func(ctx context.Context, r dgo.Repo[A]) error) error

func (*Repo[I, A, D]) VersionFieldName

func (r *Repo[I, A, D]) VersionFieldName() string

type RepoOption

type RepoOption[I repo.ID, A dgo.AggBase, D any] interface {
	// contains filtered or unexported methods
}

RepoOption[I repo.ID,A dgo.AggBase,D any] option interface

func SkipRepoOption

func SkipRepoOption[I repo.ID, A dgo.AggBase, D any]() RepoOption[I, A, D]

func WithRepoCloseTransaction

func WithRepoCloseTransaction[I repo.ID, A dgo.AggBase, D any](closeTransaction bool) RepoOption[I, A, D]

WithRepoCloseTransaction closeTransaction option of Repo

func WithRepoGetVid

func WithRepoGetVid[I repo.ID, A dgo.AggBase, D any](getVid repo.NewVid[I]) RepoOption[I, A, D]

WithRepoGetVid getVid option of Repo

func WithRepoNewAggregate

func WithRepoNewAggregate[I repo.ID, A dgo.AggBase, D any](newAggregate func() Aggregate[I, D]) RepoOption[I, A, D]

WithRepoNewAggregate newAggregate option of Repo

func WithRepoNewEvent

func WithRepoNewEvent[I repo.ID, A dgo.AggBase, D any](newEvent func() repo.Event[I]) RepoOption[I, A, D]

WithRepoNewEvent newEvent option of Repo

func WithRepoOptions

func WithRepoOptions[I repo.ID, A dgo.AggBase, D any](o *repoOptions[I, A, D]) RepoOption[I, A, D]

func WithRepoVersionFieldName

func WithRepoVersionFieldName[I repo.ID, A dgo.AggBase, D any](versionFieldName string) RepoOption[I, A, D]

WithRepoVersionFieldName versionFieldName option of Repo

type Time

type Time struct {
	time.Time
}

func WrapTime

func WrapTime(t time.Time) Time

func (*Time) MarshalBSONValue

func (t *Time) MarshalBSONValue() (bsontype.Type, []byte, error)

func (*Time) UnmarshalBSONValue

func (t *Time) UnmarshalBSONValue(bt bsontype.Type, data []byte) error

Jump to

Keyboard shortcuts

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