mutantdb

package module
v0.0.0-...-f409580 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

Functions

func Apply

func Apply[T any](d T, mutations ...Mutation[T]) (T, error)

Apply is a convenience function that applies mutations to a value.

func NewMutator

func NewMutator[T, M any](name string, fn func(T, M) (T, error)) *mutator[T, M]

Types

type Conn

type Conn interface {
	Begin(context.Context) (pgx.Tx, error)
	Exec(context.Context, string, ...any) (pgconn.CommandTag, error)
	QueryRow(context.Context, string, ...any) pgx.Row
	Query(context.Context, string, ...any) (pgx.Rows, error)
}

type Cursor

type Cursor[T any] struct {
	// contains filtered or unexported fields
}

func (Cursor[T]) Close

func (c Cursor[T]) Close()

func (Cursor[T]) Error

func (c Cursor[T]) Error() error

func (Cursor[T]) HasNext

func (c Cursor[T]) HasNext() bool

func (Cursor[T]) Next

func (c Cursor[T]) Next() (Projection[T], error)

type ErrConflict

type ErrConflict struct {
	CurrentMutationID, ExpectedMutationID string
}

func (*ErrConflict) Error

func (e *ErrConflict) Error() string

type Listener

type Listener[T any] struct {
	// contains filtered or unexported fields
}

func NewListener

func NewListener[T any](conn *pgx.Conn, t *Type[T]) *Listener[T]

func (*Listener[T]) WaitForProjection

func (l *Listener[T]) WaitForProjection(ctx context.Context) (Projection[T], error)

type Meta

type Meta map[string]string

type Mutation

type Mutation[T any] interface {
	Name() string
	Data() any
	Meta() Meta
	Apply(T) (T, error)
}

type Mutator

type Mutator[T any] interface {
	Name() string
	Apply(T, any) (T, error)
}

type Projection

type Projection[T any] struct {
	ID          string    `json:"entity_id"`
	Data        T         `json:"entity_data"`
	MutationID  string    `json:"mutation_id"`
	DateCreated time.Time `json:"date_created"`
	DateUpdated time.Time `json:"date_updated"`
}

type Store

type Store[T any] struct {
	// contains filtered or unexported fields
}

func NewStore

func NewStore[T any](conn Conn, t *Type[T]) *Store[T]

func (*Store) Append

func (s *Store) Append(ctx context.Context, entityID string, mutations ...Mutation[T]) (Projection[T], error)

func (*Store) AppendAfter

func (s *Store) AppendAfter(ctx context.Context, entityID, mutationID string, mutations ...Mutation[T]) (Projection[T], error)

func (*Store) Conn

func (s *Store) Conn() Conn

func (*Store) Get

func (s *Store) Get(ctx context.Context, id string) (Projection[T], error)

func (*Store) GetAll

func (s *Store) GetAll(ctx context.Context) (Cursor[T], error)

func (*Store) GetAt

func (s *Store) GetAt(ctx context.Context, id, mutationID string) (Projection[T], error)

func (*Store) Tx

func (s *Store) Tx(tx pgx.Tx) *store[T]

func (*Store[T]) WithIDGenerator

func (s *Store[T]) WithIDGenerator(fn func() (string, error)) *Store[T]

func (*Store[T]) WithMutators

func (s *Store[T]) WithMutators(mutators ...Mutator[T]) *Store[T]

type Type

type Type[T any] struct {
	// contains filtered or unexported fields
}

func NewType

func NewType[T any](name string, factory func() T) *Type[T]

func (*Type[T]) Name

func (t *Type[T]) Name() string

func (*Type[T]) New

func (t *Type[T]) New() T

func (*Type[T]) Validate

func (t *Type[T]) Validate(d T) error

func (*Type[T]) WithValidator

func (t *Type[T]) WithValidator(fn func(T) error) *Type[T]

Jump to

Keyboard shortcuts

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