data

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InMemoryRepository

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

InMemoryRepository implements the coffee-service.data.Repository interface uisng go-membdb instead of postgres.

func (*InMemoryRepository) Find

Find returns all coffees from the database Used to accept ctx opentracing.SpanContext

type MockRepository

type MockRepository struct {
	mock.Mock
}

MockRepository is a mock connection object for unit tests.

func (*MockRepository) Find

func (r *MockRepository) Find() (entities.Coffees, error)

Find mock stub

type PostgresRepository

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

PostgresRepository is a postgres implementation of the Repository interface.

func (*PostgresRepository) Find

Find returns all products from the database Used to accept ctx opentracing.SpanContext

type Repository

type Repository interface {
	Find() (entities.Coffees, error)
}

Repository is the command/query interface this respository supports.

func NewFromConfig

func NewFromConfig(cfg *config.Config) (Repository, error)

NewFromConfig is the CoffeeRepository factory method. It encapsulates the Postgres DB. It will attempt to create a connection, and keep retrying the database connection until successful or times out. When running the application on a scheduler it is possible (likely) that the app will come up before the database, this can cause the app to go into a CrashLoopBackoff cycle. By defining a retry loop, we are implementing circuit breaker, rather than just crashing on startup if the db is unavailable. TODO: this whole thing needs to be addressed. Probably we want to move the circuit breaking back to the lifecycle in main, and have this just test IsConnected() or just try to make the call.

func NewInMemoryDB

func NewInMemoryDB(config *config.Config) (Repository, error)

NewInMemoryDB is the InMemoryRepository factory method. It fulfills the same interface as Repository, but uses go-membdb internally to provide data. NOTE, this interface requires build time tooling.

type TableNameKey

type TableNameKey string

TableNameKey is a typesafe discriminator for table names

const (
	// Ingredient is the ingredient table name
	Ingredient TableNameKey = "ingredient"
	// Coffee is the coffee table name
	Coffee TableNameKey = "coffee"
	// CoffeeIngredient is the coffee_ingredient table name
	CoffeeIngredient TableNameKey = "coffee_ingredient"
)

func (TableNameKey) String

func (t TableNameKey) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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