Documentation ¶
Index ¶
- Constants
- Variables
- func IsNoQueryResultsError(err error) bool
- func IsRecordNotFoundError(err error) bool
- func IsTooManyResultsError(err error) bool
- func KernelMiddlewareChangeHistory(ctx context.Context, config cfg.Config, logger log.Logger) (kernel.Middleware, error)
- func MigrateChangeHistory(ctx context.Context, config cfg.Config, logger log.Logger, ...) error
- func New(config cfg.Config, logger log.Logger, s Settings) (*repository, error)
- func NewMetricRepository(_ cfg.Config, _ log.Logger, repo Repository) *metricRepository
- func NewNotifyingRepository(logger log.Logger, base Repository) *notifyingRepository
- func NewOrm(config cfg.Config, logger log.Logger) (*gorm.DB, error)
- func NewOrmWithDbSettings(logger log.Logger, dbSettings db.Settings, application string) (*gorm.DB, error)
- func NewOrmWithInterfaces(dbClient gorm.SQLCommon, settings OrmSettings) (*gorm.DB, error)
- func NewPublisherNotifier(_ context.Context, config cfg.Config, publisher Publisher, logger log.Logger, ...) *publisherNotifier
- func NewWithDbSettings(config cfg.Config, logger log.Logger, dbSettings db.Settings, ...) (*repository, error)
- func NewWithInterfaces(logger log.Logger, tracer tracing.Tracer, orm *gorm.DB, clock clock.Clock, ...) *repository
- type ChangeHistoryManager
- type ChangeHistoryModel
- type ChangeHistoryModelBased
- type FieldMapping
- func (f FieldMapping) Bool() string
- func (f FieldMapping) ColumnNames() []string
- func (f FieldMapping) Columns() []FieldMappingColumn
- func (f FieldMapping) Joins() []string
- func (f FieldMapping) WithBool(bool string) FieldMapping
- func (f FieldMapping) WithColumn(column string) FieldMapping
- func (f FieldMapping) WithColumnWithMode(column string, nullMode NullMode) FieldMapping
- func (f FieldMapping) WithJoin(join string) FieldMapping
- type FieldMappingColumn
- type FieldMappings
- type Metadata
- type Model
- type ModelBased
- type NoQueryResultsError
- type NotificationMap
- type Notifier
- type NullMode
- type OrmMigrationSetting
- type OrmSettings
- type Publisher
- type QueryBuilder
- func (qb *QueryBuilder) GroupBy(field ...string) db.QueryBuilder
- func (qb *QueryBuilder) Joins(joins []string) db.QueryBuilder
- func (qb *QueryBuilder) OrderBy(field string, direction string) db.QueryBuilder
- func (qb *QueryBuilder) Page(offset int, size int) db.QueryBuilder
- func (qb *QueryBuilder) Table(table string) db.QueryBuilder
- func (qb *QueryBuilder) Where(query interface{}, args ...interface{}) db.QueryBuilder
- type RecordNotFoundError
- type Repository
- type RepositoryReadOnly
- type Settings
- type TimeStampable
- type TimestampAware
- type Timestamps
- type TooManyResultsError
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 IsRecordNotFoundError ¶
func IsTooManyResultsError ¶
func MigrateChangeHistory ¶
func NewMetricRepository ¶
func NewMetricRepository(_ cfg.Config, _ log.Logger, repo Repository) *metricRepository
func NewNotifyingRepository ¶
func NewNotifyingRepository(logger log.Logger, base Repository) *notifyingRepository
func NewOrmWithDbSettings ¶
func NewOrmWithInterfaces ¶
func NewPublisherNotifier ¶
func NewWithDbSettings ¶
Types ¶
type ChangeHistoryManager ¶
type ChangeHistoryManager struct {
// contains filtered or unexported fields
}
func NewChangeHistoryManager ¶
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 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 }
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 Notifier ¶
type Notifier interface {
Send(ctx context.Context, notificationType string, value ModelBased) error
}
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 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 TimeStampable ¶
type TimestampAware ¶
type Timestamps ¶
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
Source Files ¶
Click to show internal directories.
Click to hide internal directories.