postgres

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInsertInsteadOfUpsert = errors.New("insert instead of upsert")
	ErrInsertNotImplemented  = errors.New("insert not implemented")
)
View Source
var (
	// ErrModelNotSet is when a model factory is not set on the Repo.
	ErrModelNotSet = errors.New("model not set")
)

Functions

This section is empty.

Types

type Option

type Option[T eh.Entity] func(*Repo[T]) error

Option is an option setter used to configure creation.

func WithConnectionCheck

func WithConnectionCheck[T eh.Entity](h eh.EventHandler) Option[T]

WithConnectionCheck adds an optional DB connection check when calling New().

type Querier

type Querier[T eh.Entity] interface {
	List(ctx context.Context) ([]T, error)
	Get(ctx context.Context, id uuid.UUID) (T, error)
	Upsert(ctx context.Context, entity T) error
	Insert(ctx context.Context, entity T) error
	Delete(ctx context.Context, id uuid.UUID) error
}

type Repo

type Repo[T eh.Entity] struct {
	// contains filtered or unexported fields
}

Repo implements an MongoDB repository for entities.

func IntoRepo

func IntoRepo[T eh.Entity](ctx context.Context, repo eh.ReadRepo) *Repo[T]

IntoRepo tries to convert a eh.ReadRepo into a Repo by recursively looking at inner repos. Returns nil if none was found.

func NewRepo

func NewRepo[T eh.Entity](ctx context.Context, uri, table string, initQuerier func(*pgxpool.Pool) Querier[T], options ...Option[T]) (*Repo[T], error)

NewRepo creates a new Repo.

func NewRepoWithConnPool

func NewRepoWithConnPool[T eh.Entity](connPool *pgxpool.Pool, table string, initQuerier func(*pgxpool.Pool) Querier[T], options ...Option[T]) (*Repo[T], error)

NewRepoWithClient creates a new Repo with a client.

func (*Repo[T]) Clear

func (r *Repo[T]) Clear(ctx context.Context) error

Clear clears the read model database.

func (*Repo[T]) Close

func (r *Repo[T]) Close() error

Close implements the Close method of the eventhorizon.WriteRepo interface.

func (*Repo[T]) Find

func (r *Repo[T]) Find(ctx context.Context, id uuid.UUID) (eh.Entity, error)

Find implements the Find method of the eventhorizon.ReadRepo interface.

func (*Repo[T]) FindAll

func (r *Repo[T]) FindAll(ctx context.Context) ([]eh.Entity, error)

FindAll implements the FindAll method of the eventhorizon.ReadRepo interface.

func (*Repo[T]) InnerRepo

func (r *Repo[T]) InnerRepo(ctx context.Context) eh.ReadRepo

InnerRepo implements the InnerRepo method of the eventhorizon.ReadRepo interface.

func (*Repo[T]) Remove

func (r *Repo[T]) Remove(ctx context.Context, id uuid.UUID) error

Remove implements the Remove method of the eventhorizon.WriteRepo interface.

func (*Repo[T]) Save

func (r *Repo[T]) Save(ctx context.Context, entity eh.Entity) error

Save implements the Save method of the eventhorizon.WriteRepo interface.

Jump to

Keyboard shortcuts

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