Documentation ¶
Index ¶
- Constants
- Variables
- func Initdb(log *slog.Logger, db *sqlx.DB, healthServer *health.Server, dir string) error
- func IsErrorCode(err error, errcode pq.ErrorCode) bool
- func MigrateDB(log *slog.Logger, db *sqlx.DB, healthServer *health.Server) error
- func NewPostgresDB(logger *slog.Logger, host, port, user, password, dbname, sslmode string, ...) (*sqlx.DB, error)
- func RunQuery[E any](ctx context.Context, log *slog.Logger, db *sqlx.DB, ...) error
- type DataCorruptionError
- type DuplicateKeyError
- type Entity
- type MetaMeta
- type NotFoundError
- type Op
- type OptimisticLockError
- type Storage
Constants ¶
const ( // UniqueViolationError is raised if the unique constraint is violated UniqueViolationError = pq.ErrorCode("23505") // 'unique_violation' )
Variables ¶
var Now = time.Now
exchangeable for testing
Functions ¶
func Initdb ¶ added in v0.10.0
Initdb reads all yaml files in given directory and apply their content as initial datasets.
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 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 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[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 DeleteAll(ctx context.Context, ids ...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.