firestore

package module
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

README

pipeline status coverage report GoDoc Go Report Card

eh-firestore

eh-firestore contains a Google Cloud Firestore for the Event Horizon CQRS/ES toolkit for Go.

Usage

See the Event Horizon example folder for a few examples to get you started and replace the storage drivers (event store and/or repo)

Development

To develop eh-firestore you need to have Docker and Docker Compose installed.

To start all required services and run all tests, simply run make:

make

To manually start services for local development outside Docker:

make services

You can then run either one of the following:

make test
make _test
go test ./...

or use your favourite IDE to run your tests with a Cloud Firestore emulator in the background.

Documentation

Index

Constants

View Source
const (
	// FieldCreated the name of the field tracking when an entity was created
	FieldCreated = "_created"

	// FieldUpdated the name of the field tracking when an entity was updated
	FieldUpdated = "_updated"
)

Variables

View Source
var (
	// ErrCouldNotSaveAggregate is when an aggregate could not be saved.
	ErrCouldNotSaveAggregate = errors.New("could not save aggregate")
	// ErrCouldNotUnmarshalAggregate is when an aggregate could not be unmarshaled into a concrete type.
	ErrCouldNotUnmarshalAggregate = errors.New("could not unmarshal aggregate")
	// ErrCouldNotMarshalEvent is when an event could not be marshaled into JSON
	ErrCouldNotMarshalEvent = errors.New("could not marshal event")
	// ErrCouldNotUnmarshalEvent is when an event could not be unmarshaled into a concrete type.
	ErrCouldNotUnmarshalEvent = errors.New("could not unmarshal event")
)
View Source
var ErrCouldNotConvertData = errors.New("could not convert data")

ErrCouldNotConvertData is when data could not be converted

View Source
var ErrCouldNotDialDB = errors.New("could not dial database")

ErrCouldNotDialDB is when the database could not be dialed.

View Source
var ErrInvalidQuery = errors.New("invalid query")

ErrInvalidQuery is when a query was not returned from the callback to FindCustom.

View Source
var ErrModelNotSet = errors.New("model not set")

ErrModelNotSet is when an model factory is not set on the Repo.

View Source
var ErrNoDBClient = errors.New("no database client")

ErrNoDBClient is when no database client is set.

Functions

This section is empty.

Types

type EventStore

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

EventStore implements an EventStore for Firestore

func NewEventStore

func NewEventStore(projectID, prefix string, opts ...option.ClientOption) (*EventStore, error)

NewEventStore creates a new EventStore with optional GCP connection settings

func NewEventStoreWithClient

func NewEventStoreWithClient(prefix string, client *firestore.Client) *EventStore

NewEventStoreWithClient creates a new EventStore with DB

func (*EventStore) Clear

func (s *EventStore) Clear(ctx context.Context) error

func (*EventStore) Close

func (s *EventStore) Close(ctx context.Context)

func (*EventStore) Load

func (s *EventStore) Load(ctx context.Context, id uuid.UUID) ([]eh.Event, error)

Load implements the Load method of the eventhorizon.EventStore interface.

func (*EventStore) RenameEvent

func (s *EventStore) RenameEvent(ctx context.Context, from, to eh.EventType) error

RenameEvent implements the RenameEvent method of the eventhorizon.EventStore interface.

func (*EventStore) Replace

func (s *EventStore) Replace(ctx context.Context, event eh.Event) error

Replace implements the Replace method of the eventhorizon.EventStore interface.

func (*EventStore) Save

func (s *EventStore) Save(ctx context.Context, events []eh.Event, originalVersion int) error

Save implements the Save method of the eventhorizon.EventStore interface

type Repo

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

Repo implements a Cloud Firestore repository for entities

func NewRepo

func NewRepo(projectID, collection string, opts ...option.ClientOption) (*Repo, error)

NewRepo created a new Repo.

func NewRepoWithClient

func NewRepoWithClient(collection string, client *firestore.Client) (*Repo, error)

NewRepoWithClient created a new Repo with a client.

func (*Repo) Find

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

Find implements the Find method of the eventhorizon.ReadRepo interface

func (*Repo) FindAll

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

FindAll implements the FindAll method of the eventhorizon.ReadRepo interface

func (*Repo) FindCustom

func (r *Repo) FindCustom(ctx context.Context, callback func(*firestore.CollectionRef) *firestore.Query) ([]interface{}, error)

FindCustom uses a callback to specify a custom query for returning models. It can also be used to do queries that do not map to the model by executing the query in the callback and returning nil to block the second execution of the same query in FindCustom. Expect a ErrInvalidQuery if returning a nil query from the callback

func (*Repo) FindCustomIter

func (r *Repo) FindCustomIter(ctx context.Context, callback func(*firestore.CollectionRef) *firestore.Query) (eh.Iter, error)

FindCustomIter returns a curser you can use to stream results of very large datasets

func (*Repo) Parent

func (r *Repo) Parent() eh.ReadRepo

Parent implements the Parent method of the eventhorizon.ReadRepo interface

func (*Repo) Remove

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

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

func (*Repo) Save

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

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

func (*Repo) SetEntityFactory

func (r *Repo) SetEntityFactory(f func() eh.Entity)

SetEntityFactory sets a factory function that creates concrete entity types.

Jump to

Keyboard shortcuts

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