mongosnap

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when a Snapshot can't be found in the database.
	ErrNotFound = errors.New("snapshot not found")
)

Functions

This section is empty.

Types

type Option

type Option func(*Store)

Option is a Store option.

func Collection

func Collection(name string) Option

Collection returns an Option that specifies the collection name for Snapshots.

func Database

func Database(name string) Option

Database returns an Option that specifies the database name for Snapshots.

func URL

func URL(url string) Option

URL returns an Option that specifies the URL to the MongoDB instance. An empty URL means "use the default".

Defaults to the environment variable "MONGO_URL".

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is the MongoDB implementation of snapshot.Store.

func New

func New(opts ...Option) *Store

New returns a new Store.

func (*Store) Connect

func (s *Store) Connect(ctx context.Context) (*mongo.Client, error)

Connect establishes the connection to the underlying MongoDB and returns the mongo.Client. Connect doesn't need to be called manually as it's called automatically on the first call to s.Save, s.Latest, s.Version, s.Query or s.Delete. Use Connect if you want to explicitly control when to connect to MongoDB.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, snap snapshot.Snapshot) error

Delete deletes a Snapshot from the database.

func (*Store) Latest

func (s *Store) Latest(ctx context.Context, name string, id uuid.UUID) (snapshot.Snapshot, error)

Latest returns the latest Snapshot for the Aggregate with the given name and UUID or ErrNotFound if no Snapshots for that Aggregate exist in the database.

func (*Store) Limit

func (s *Store) Limit(ctx context.Context, name string, id uuid.UUID, v int) (snapshot.Snapshot, error)

Limit returns the latest Snapshot that has a version equal to or lower than the given version.

Limit returns ErrNotFound if no such Snapshot can be found in the database.

func (*Store) Query

func (s *Store) Query(ctx context.Context, q snapshot.Query) (<-chan snapshot.Snapshot, <-chan error, error)

func (*Store) Save

func (s *Store) Save(ctx context.Context, snap snapshot.Snapshot) error

Save saves the given Snapshot into the database.

func (*Store) Version

func (s *Store) Version(ctx context.Context, name string, id uuid.UUID, version int) (snapshot.Snapshot, error)

Version returns the Snapshot for the Aggregate with the given name, UUID and version. If no Snapshot for the given version exists, Version returns ErrNotFound.

Jump to

Keyboard shortcuts

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