Documentation
¶
Index ¶
- Constants
- Variables
- func IsErrorCode(err error, errcode pq.ErrorCode) bool
- func PbNow() (*timestamp.Timestamp, time.Time)
- type DataCorruptionError
- type Datastore
- func (ds *Datastore) Create(ctx context.Context, ve VersionedJSONEntity) error
- func (ds *Datastore) Delete(ctx context.Context, ve VersionedJSONEntity) error
- func (ds *Datastore) Find(ctx context.Context, filter map[string]interface{}, result interface{}) error
- func (ds *Datastore) Get(ctx context.Context, id string, ve VersionedJSONEntity) error
- func (ds *Datastore) GetHistory(ctx context.Context, id string, at time.Time, ve VersionedJSONEntity) error
- func (ds *Datastore) GetHistoryCreated(ctx context.Context, id string, ve VersionedJSONEntity) error
- func (ds *Datastore) Initdb(healthServer *health.Server, dir string) error
- func (ds *Datastore) MigrateDB(healthServer *health.Server) error
- func (ds *Datastore) Update(ctx context.Context, ve VersionedJSONEntity) error
- type DuplicateKeyError
- type JSONEntity
- type MetaMeta
- type NotFoundError
- type Op
- type OptimisticLockError
- type Storage
- type VersionedEntity
- type VersionedJSONEntity
Constants ¶
const ( // UniqueViolationError is raised if the unique constraint is violated UniqueViolationError = pq.ErrorCode("23505") // 'unique_violation' )
Variables ¶
var Now = time.Now
exchangable for testing
Functions ¶
func IsErrorCode ¶ added in v0.7.2
IsErrorCode a specific postgres specific error as defined by https://www.postgresql.org/docs/12/errcodes-appendix.html
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) 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 ¶
Initdb reads all yaml files in given directory and apply their content as initial datasets.
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 ¶
JSONEntity is storable in json format
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 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 ¶
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