datastore

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 21 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

exchangeable for testing

Functions

func Initdb added in v0.10.0

func Initdb(log *slog.Logger, db *sqlx.DB, healthServer *health.Server, dir string) error

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

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 MigrateDB added in v0.10.0

func MigrateDB(log *slog.Logger, db *sqlx.DB, healthServer *health.Server) error

MigrateDB applies necessary DB Migrations.

func NewPostgresDB added in v0.10.0

func NewPostgresDB(logger *slog.Logger, host, port, user, password, dbname, sslmode string, ves ...Entity) (*sqlx.DB, error)

NewPostgresStorage creates a new Storage which uses postgres.

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 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 Entity added in v0.10.0

type Entity interface {
	JSONField() string
	TableName() string
	Schema() string
	GetMeta() *v1.Meta
	Kind() string
	APIVersion() string
}

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

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[E Entity] interface {
	// generic
	Create(ctx context.Context, ve E) error
	Update(ctx context.Context, ve E) error
	Delete(ctx context.Context, id string) error
	Get(ctx context.Context, id string) (E, error)
	GetHistory(ctx context.Context, id string, at time.Time, ve E) error
	GetHistoryCreated(ctx context.Context, id string, ve E) error
	Find(ctx context.Context, filter map[string]any, paging *v1.Paging) ([]E, *uint64, error)
}

Storage is a interface to store objects.

func New added in v0.10.0

func New[E Entity](logger *slog.Logger, db *sqlx.DB, e E) (Storage[E], error)

New creates a new Storage which uses the given database abstraction.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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