db_repo

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BoolAnd = "AND"
	BoolOr  = "OR"

	// Nulls will be treated like SQL defines them. null != 1 yields null
	NullModeDefault = 0
	// Nulls will be treated like Go defines them. null != 1 yields true
	NullModeDistinct = 1
)
View Source
const (
	MetricNameDbAccessSuccess = "DbAccessSuccess"
	MetricNameDbAccessFailure = "DbAccessFailure"
	MetricNameDbAccessLatency = "DbAccessLatency"
)
View Source
const (
	Create = "create"
	Read   = "read"
	Update = "update"
	Delete = "delete"
	Query  = "query"
)
View Source
const ColumnUpdatedAt = "updated_at"

Variables

View Source
var (
	ErrCrossQuery  = fmt.Errorf("cross querying wrong model from repo")
	ErrCrossCreate = fmt.Errorf("cross creating wrong model from repo")
	ErrCrossRead   = fmt.Errorf("cross reading wrong model from repo")
	ErrCrossDelete = fmt.Errorf("cross deleting wrong model from repo")
	ErrCrossUpdate = fmt.Errorf("cross updating wrong model from repo")
)
View Source
var NotificationTypes = []string{Create, Update, Delete}

Functions

func IsNoQueryResultsError

func IsNoQueryResultsError(err error) bool

func IsRecordNotFoundError

func IsRecordNotFoundError(err error) bool

func IsTooManyResultsError

func IsTooManyResultsError(err error) bool

func KernelMiddlewareChangeHistory

func KernelMiddlewareChangeHistory(ctx context.Context, config cfg.Config, logger log.Logger) (kernel.Middleware, error)

func MigrateChangeHistory

func MigrateChangeHistory(ctx context.Context, config cfg.Config, logger log.Logger, models ...ModelBased) error

func New

func New(config cfg.Config, logger log.Logger, s Settings) (*repository, error)

func NewMetricRepository

func NewMetricRepository(_ cfg.Config, _ log.Logger, repo Repository) *metricRepository

func NewNotifyingRepository

func NewNotifyingRepository(logger log.Logger, base Repository) *notifyingRepository

func NewOrm

func NewOrm(config cfg.Config, logger log.Logger) (*gorm.DB, error)

func NewOrmWithDbSettings

func NewOrmWithDbSettings(logger log.Logger, dbSettings db.Settings, application string) (*gorm.DB, error)

func NewOrmWithInterfaces

func NewOrmWithInterfaces(dbClient gorm.SQLCommon, settings OrmSettings) (*gorm.DB, error)

func NewPublisherNotifier

func NewPublisherNotifier(_ context.Context, config cfg.Config, publisher Publisher, logger log.Logger, modelId mdl.ModelId, version int, transformer mdl.TransformerResolver) *publisherNotifier

func NewWithDbSettings

func NewWithDbSettings(config cfg.Config, logger log.Logger, dbSettings db.Settings, repoSettings Settings) (*repository, error)

func NewWithInterfaces

func NewWithInterfaces(logger log.Logger, tracer tracing.Tracer, orm *gorm.DB, clock clock.Clock, metadata Metadata) *repository

Types

type ChangeHistoryManager

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

func NewChangeHistoryManager

func NewChangeHistoryManager(config cfg.Config, logger log.Logger) (*ChangeHistoryManager, error)

func ProvideChangeHistoryManager

func ProvideChangeHistoryManager(ctx context.Context, config cfg.Config, logger log.Logger) (*ChangeHistoryManager, error)

func (*ChangeHistoryManager) RunMigration

func (c *ChangeHistoryManager) RunMigration(model ModelBased) error

func (*ChangeHistoryManager) RunMigrations

func (c *ChangeHistoryManager) RunMigrations() error

type ChangeHistoryModel

type ChangeHistoryModel struct {
	ChangeHistoryAction   string    `sql:"type: VARCHAR(8) NOT NULL DEFAULT 'insert'"`
	ChangeHistoryActionAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
	ChangeHistoryRevision int       `gorm:"primary_key"`
}

func (*ChangeHistoryModel) GetHistoryAction

func (c *ChangeHistoryModel) GetHistoryAction() string

func (*ChangeHistoryModel) GetHistoryActionAt

func (c *ChangeHistoryModel) GetHistoryActionAt() time.Time

func (*ChangeHistoryModel) GetHistoryRevision

func (c *ChangeHistoryModel) GetHistoryRevision() int

type ChangeHistoryModelBased

type ChangeHistoryModelBased interface {
	GetHistoryAction() string
	GetHistoryActionAt() time.Time
	GetHistoryRevision() int
}

type FieldMapping

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

func NewFieldMapping

func NewFieldMapping(column string) FieldMapping

func NewFieldMappingWithMode

func NewFieldMappingWithMode(column string, nullMode NullMode) FieldMapping

func (FieldMapping) Bool

func (f FieldMapping) Bool() string

func (FieldMapping) ColumnNames

func (f FieldMapping) ColumnNames() []string

func (FieldMapping) Columns

func (f FieldMapping) Columns() []FieldMappingColumn

func (FieldMapping) Joins

func (f FieldMapping) Joins() []string

func (FieldMapping) WithBool

func (f FieldMapping) WithBool(bool string) FieldMapping

func (FieldMapping) WithColumn

func (f FieldMapping) WithColumn(column string) FieldMapping

func (FieldMapping) WithColumnWithMode

func (f FieldMapping) WithColumnWithMode(column string, nullMode NullMode) FieldMapping

func (FieldMapping) WithJoin

func (f FieldMapping) WithJoin(join string) FieldMapping

type FieldMappingColumn

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

func (FieldMappingColumn) Name

func (c FieldMappingColumn) Name() string

func (FieldMappingColumn) NullMode

func (c FieldMappingColumn) NullMode() NullMode

type FieldMappings

type FieldMappings map[string]FieldMapping

type Metadata

type Metadata struct {
	ModelId    mdl.ModelId
	TableName  string
	PrimaryKey string
	Mappings   FieldMappings
}

type Model

type Model struct {
	Id *uint `gorm:"primary_key;AUTO_INCREMENT"`
	Timestamps
}

func (*Model) GetId

func (m *Model) GetId() *uint

type ModelBased

type ModelBased interface {
	mdl.Identifiable
	TimeStampable
}

type NoQueryResultsError

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

func NewNoQueryResultsError

func NewNoQueryResultsError(modelId string, err error) NoQueryResultsError

func (NoQueryResultsError) Error

func (e NoQueryResultsError) Error() string

func (NoQueryResultsError) Unwrap

func (e NoQueryResultsError) Unwrap() error

type NotificationMap

type NotificationMap map[string][]Notifier

type Notifier

type Notifier interface {
	Send(ctx context.Context, notificationType string, value ModelBased) error
}

type NullMode

type NullMode int

type OrmMigrationSetting

type OrmMigrationSetting struct {
	TablePrefixed bool `cfg:"table_prefixed" default:"true"`
}

type OrmSettings

type OrmSettings struct {
	Migrations  OrmMigrationSetting `cfg:"migrations"`
	Driver      string              `cfg:"driver" validation:"required"`
	Application string              `cfg:"application" default:"{app_name}"`
}

type Publisher

type Publisher interface {
	Publish(ctx context.Context, typ string, version int, value interface{}, customAttributes ...map[string]string) error
}

type QueryBuilder

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

func NewQueryBuilder

func NewQueryBuilder() *QueryBuilder

func (*QueryBuilder) GroupBy

func (qb *QueryBuilder) GroupBy(field ...string) db.QueryBuilder

func (*QueryBuilder) Joins

func (qb *QueryBuilder) Joins(joins []string) db.QueryBuilder

func (*QueryBuilder) OrderBy

func (qb *QueryBuilder) OrderBy(field string, direction string) db.QueryBuilder

func (*QueryBuilder) Page

func (qb *QueryBuilder) Page(offset int, size int) db.QueryBuilder

func (*QueryBuilder) Table

func (qb *QueryBuilder) Table(table string) db.QueryBuilder

func (*QueryBuilder) Where

func (qb *QueryBuilder) Where(query interface{}, args ...interface{}) db.QueryBuilder

type RecordNotFoundError

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

func NewRecordNotFoundError

func NewRecordNotFoundError(id uint, modelId string, err error) RecordNotFoundError

func (RecordNotFoundError) Error

func (e RecordNotFoundError) Error() string

func (RecordNotFoundError) Unwrap

func (e RecordNotFoundError) Unwrap() error

type Repository

type Repository interface {
	RepositoryReadOnly
	Create(ctx context.Context, value ModelBased) error
	Update(ctx context.Context, value ModelBased) error
	Delete(ctx context.Context, value ModelBased) error
}

type RepositoryReadOnly

type RepositoryReadOnly interface {
	Read(ctx context.Context, id *uint, out ModelBased) error
	Query(ctx context.Context, qb *QueryBuilder, result interface{}) error
	Count(ctx context.Context, qb *QueryBuilder, model ModelBased) (int, error)

	GetModelId() string
	GetModelName() string
	GetMetadata() Metadata
}

type Settings

type Settings struct {
	cfg.AppId
	Metadata Metadata
}

type TimeStampable

type TimeStampable interface {
	SetUpdatedAt(updatedAt *time.Time)
	SetCreatedAt(createdAt *time.Time)
}

type TimestampAware

type TimestampAware interface {
	GetCreatedAt() *time.Time
	GetUpdatedAt() *time.Time
}

type Timestamps

type Timestamps struct {
	UpdatedAt *time.Time
	CreatedAt *time.Time
}

func EmptyTimestamps

func EmptyTimestamps() Timestamps

func (*Timestamps) GetCreatedAt

func (m *Timestamps) GetCreatedAt() *time.Time

func (*Timestamps) GetUpdatedAt

func (m *Timestamps) GetUpdatedAt() *time.Time

func (*Timestamps) SetCreatedAt

func (m *Timestamps) SetCreatedAt(createdAt *time.Time)

func (*Timestamps) SetUpdatedAt

func (m *Timestamps) SetUpdatedAt(updatedAt *time.Time)

type TooManyResultsError

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

func NewTooManyResultsError

func NewTooManyResultsError(found int, expected int, modelId string) TooManyResultsError

func (TooManyResultsError) Error

func (e TooManyResultsError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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