datastore

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2020 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UniqueViolationError is raised if the unique constraint is violated
	UniqueViolationError = pq.ErrorCode("23505") // 'unique_violation'
)

Variables

View Source
var Now = time.Now

exchangable for testing

Functions

func IsErrorCode added in v0.7.2

func IsErrorCode(err error, errcode pq.ErrorCode) bool

IsErrorCode a specific postgres specific error as defined by https://www.postgresql.org/docs/12/errcodes-appendix.html

func PbNow added in v0.7.0

func PbNow() (*timestamp.Timestamp, time.Time)

PbNow returns the current time as Protobuf and time

Types

type DataCorruptionError

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

DataCorruptionError indicates that the data is in an unexpected, illegal state

func NewDataCorruptionError

func NewDataCorruptionError(msg string) DataCorruptionError

NewDataCorruptionError is called to create an DataCorruptionError error

func (DataCorruptionError) Error

func (o DataCorruptionError) Error() string

type Datastore

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

Datastore is the adapter to talk to the database

func NewPostgresStorage

func NewPostgresStorage(logger *zap.Logger, host, port, user, password, dbname, sslmode string, ves ...VersionedJSONEntity) (*Datastore, error)

NewPostgresStorage creates a new Storage which uses postgres.

func (*Datastore) Create

func (ds *Datastore) Create(ctx context.Context, ve VersionedJSONEntity) error

Create a entity

func (*Datastore) Delete

func (ds *Datastore) Delete(ctx context.Context, ve VersionedJSONEntity) error

Delete deletes the entity

func (*Datastore) Find

func (ds *Datastore) Find(ctx context.Context, filter map[string]interface{}, result interface{}) error

Find returns matching elements from the database

func (*Datastore) Get

Get the entity for given id returns NotFoundError if no entity can be found

func (*Datastore) GetHistory added in v0.7.0

func (ds *Datastore) GetHistory(ctx context.Context, id string, at time.Time, ve VersionedJSONEntity) error

Get the history entity for given id and latest before or equal the given point in time returns NotFoundError if no entity can be found

func (*Datastore) GetHistoryCreated added in v0.7.1

func (ds *Datastore) GetHistoryCreated(ctx context.Context, id string, ve VersionedJSONEntity) error

Get the first history entity for given id, returns NotFoundError if no entity can be found

func (*Datastore) Initdb

func (ds *Datastore) Initdb(healthServer *health.Server, dir string) error

Initdb reads all yaml files in given directory and apply their content as initial datasets.

func (*Datastore) MigrateDB added in v0.7.1

func (ds *Datastore) MigrateDB(healthServer *health.Server) error

MigrateDB applies necessary DB Migrations.

func (*Datastore) Update

func (ds *Datastore) Update(ctx context.Context, ve VersionedJSONEntity) error

Update the entity

type DuplicateKeyError

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

DuplicateKeyError indicates that an entity with the given id already exists

func NewDuplicateKeyError

func NewDuplicateKeyError(msg string) DuplicateKeyError

NewDuplicateKeyError is called to create an DuplicateKeyError error

func (DuplicateKeyError) Error

func (o DuplicateKeyError) Error() string

type JSONEntity

type JSONEntity interface {
	JSONField() string
	TableName() string
	Schema() string
}

JSONEntity is storable in json format

type MetaMeta

type MetaMeta struct {
	v1.Meta `json:"meta" yaml:"meta"`
}

MetaMeta is a container for the meta property inside a entity.

type NotFoundError

type NotFoundError struct {
	Err error
	// contains filtered or unexported fields
}

NotFoundError indicates that the entity that was expected to be affected by the operation was not found

func NewNotFoundError

func NewNotFoundError(msg string) NotFoundError

NewNotFoundError is called to create an NewNotFoundError error

func (NotFoundError) Error

func (e NotFoundError) Error() string

type Op added in v0.7.0

type Op string

type OptimisticLockError

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

OptimisticLockError indicates that the operation could not be executed because the dataset to update has changed in the meantime. clients can decide to read the current dataset and retry the operation.

func NewOptimisticLockError

func NewOptimisticLockError(msg string) OptimisticLockError

NewOptimisticLockError is called to create an OptimisticLockError error

func (OptimisticLockError) Error

func (o OptimisticLockError) Error() string

type Storage

type Storage interface {
	// generic
	Create(ctx context.Context, ve VersionedJSONEntity) error
	Update(ctx context.Context, ve VersionedJSONEntity) error
	Delete(ctx context.Context, ve VersionedJSONEntity) error
	Get(ctx context.Context, id string, ve VersionedJSONEntity) error
	GetHistory(ctx context.Context, id string, at time.Time, ve VersionedJSONEntity) error
	Find(ctx context.Context, filter map[string]interface{}, result interface{}) error
}

Storage is a interface to store objects.

type VersionedEntity

type VersionedEntity interface {
	GetMeta() *v1.Meta
	Kind() string
	APIVersion() string
}

VersionedEntity defines a database entity which is stored with version information

type VersionedJSONEntity

type VersionedJSONEntity interface {
	JSONEntity
	VersionedEntity
}

VersionedJSONEntity defines a database entity which is stored in jsonb format and with version information

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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