gorm

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2022 License: Apache-2.0 Imports: 28 Imported by: 3 modules, 11 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ConcurrentUpdateCode = "CONCURRENT_UPDATE"
)
View Source
const (
	DefaultSlowThreshold = 200 * time.Millisecond
)

Variables

View Source
var (
	ErrConcurrency = kerrors.Conflict(ConcurrentUpdateCode, "")
)

Functions

func BuildBooleanFilter

func BuildBooleanFilter(field string, filter *query.BooleanFilterOperators) func(db *gorm.DB) *gorm.DB

func BuildDateFilter

func BuildDateFilter(field string, filter *query.DateFilterOperators) func(db *gorm.DB) *gorm.DB

func BuildDoubleFilter

func BuildDoubleFilter(field string, filter *query.DoubleFilterOperators) func(db *gorm.DB) *gorm.DB

func BuildFloatFilter

func BuildFloatFilter(field string, filter *query.FloatFilterOperators) func(db *gorm.DB) *gorm.DB

func BuildInt32Filter

func BuildInt32Filter(field string, filter *query.Int32FilterOperators) func(db *gorm.DB) *gorm.DB

func BuildInt64Filter

func BuildInt64Filter(field string, filter *query.Int64FilterOperators) func(db *gorm.DB) *gorm.DB

func BuildNullFilter

func BuildNullFilter(field string, filter *query.NullFilterOperators) func(db *gorm.DB) *gorm.DB

func BuildStringFilter

func BuildStringFilter(field string, filter *query.StringFilterOperation) func(db *gorm.DB) *gorm.DB

func NewConnStrResolver

func NewConnStrResolver(c *conf.Endpoints, ts saas.TenantStore) data.ConnStrResolver

func NewDbGuardianContext

func NewDbGuardianContext(ctx context.Context, enable ...bool) context.Context

NewDbGuardianContext flag for database auto creation

func NewDbProvider

func NewDbProvider(cache *DbCache, cs data.ConnStrResolver, d *conf.Data) sgorm.DbProvider

func PageScope

func PageScope(page query.Page) func(db *gorm.DB) *gorm.DB

func RegisterCallbacks

func RegisterCallbacks(db *gorm.DB)

RegisterCallbacks register callback into GORM DB

func SortScope

func SortScope(sort query.Sort, d []string) func(db *gorm.DB) *gorm.DB

SortScope build sorting by sort and default d

func WhereUserId

func WhereUserId(id interface{}) func(db *gorm.DB) *gorm.DB

WhereUserId append 'user_id' field filter

Types

type AuditedModel

type AuditedModel struct {
	CreatedBy *string
	UpdatedBy *string
	CreatedAt time.Time `gorm:"timestamp"`
	UpdatedAt time.Time `gorm:"timestamp"`
}

AuditedModel make Model Auditable, embed `audited.AuditedModel` into your model as anonymous field to make the model auditable

type User struct {
  gorm.AuditedModel
}

func (AuditedModel) GetCreatedBy

func (model AuditedModel) GetCreatedBy() *string

GetCreatedBy get created by

func (AuditedModel) GetUpdatedBy

func (model AuditedModel) GetUpdatedBy() *string

GetUpdatedBy get updated by

func (*AuditedModel) SetCreatedBy

func (model *AuditedModel) SetCreatedBy(createdBy interface{})

SetCreatedBy set created by

func (*AuditedModel) SetUpdatedBy

func (model *AuditedModel) SetUpdatedBy(updatedBy interface{})

SetUpdatedBy set updated by

type BuildDetailScope

type BuildDetailScope interface {
	BuildDetailScope(withDetail bool) func(db *gorm.DB) *gorm.DB
}

type BuildFilterScope

type BuildFilterScope[TQuery any] interface {
	BuildFilterScope(q *TQuery) func(db *gorm.DB) *gorm.DB
}

type BuildPageScope

type BuildPageScope[TQuery any] interface {
	BuildPageScope(q *TQuery) func(db *gorm.DB) *gorm.DB
}

type BuildSortScope

type BuildSortScope[TQuery any] interface {
	BuildSortScope(q *TQuery) func(db *gorm.DB) *gorm.DB
}

type DbCache

type DbCache struct {
	*saas.Cache[string, *sgorm.DbWrap]
	// contains filtered or unexported fields
}

func NewDbCache

func NewDbCache(d *conf.Data, l klog.Logger) (*DbCache, func())

NewDbCache create a shared gorm.Db cache by dsn

func (*DbCache) GetOrSet

func (c *DbCache) GetOrSet(ctx context.Context, key, connStr string) (*gorm.DB, error)

type DbProviderFunc

type DbProviderFunc func(ctx context.Context, key string) *gorm.DB

func (DbProviderFunc) Get

func (d DbProviderFunc) Get(ctx context.Context, key string) *gorm.DB

type DefaultSorting

type DefaultSorting interface {
	DefaultSorting() []string
}

type GetDb

type GetDb interface {
	GetDb(ctx context.Context) *gorm.DB
}

type Logger

type Logger struct {
	klog.Logger
	LogLevel      logger.LogLevel
	SlowThreshold time.Duration
}

func (*Logger) Error

func (l *Logger) Error(ctx context.Context, s string, i ...interface{})

func (*Logger) Info

func (l *Logger) Info(ctx context.Context, s string, i ...interface{})

func (*Logger) LogMode

func (l *Logger) LogMode(level logger.LogLevel) logger.Interface

func (*Logger) Trace

func (l *Logger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)

func (*Logger) Warn

func (l *Logger) Warn(ctx context.Context, s string, i ...interface{})

type Repo

type Repo[TEntity any, TKey any, TQuery any] struct {
	DbProvider sgorm.DbProvider
	Eventbus   *eventbus.EventBus
	// contains filtered or unexported fields
}

func NewRepo

func NewRepo[TEntity any, TKey any, TQuery any](dbProvider sgorm.DbProvider, eventbus *eventbus.EventBus, override interface{}) *Repo[TEntity, TKey, TQuery]

func (*Repo[TEntity, TKey, TQuery]) BatchCreate

func (r *Repo[TEntity, TKey, TQuery]) BatchCreate(ctx context.Context, entity []*TEntity, batchSize int) error

func (*Repo[TEntity, TKey, TQuery]) Count

func (r *Repo[TEntity, TKey, TQuery]) Count(ctx context.Context, query *TQuery) (total int64, filtered int64, err error)

func (*Repo[TEntity, TKey, TQuery]) Create

func (r *Repo[TEntity, TKey, TQuery]) Create(ctx context.Context, entity *TEntity) error

func (*Repo[TEntity, TKey, TQuery]) Delete

func (r *Repo[TEntity, TKey, TQuery]) Delete(ctx context.Context, id TKey) error

func (*Repo[TEntity, TKey, TQuery]) First

func (r *Repo[TEntity, TKey, TQuery]) First(ctx context.Context, query *TQuery) (*TEntity, error)

func (*Repo[TEntity, TKey, TQuery]) Get

func (r *Repo[TEntity, TKey, TQuery]) Get(ctx context.Context, id TKey) (*TEntity, error)

func (*Repo[TEntity, TKey, TQuery]) List

func (r *Repo[TEntity, TKey, TQuery]) List(ctx context.Context, query *TQuery) ([]*TEntity, error)

func (*Repo[TEntity, TKey, TQuery]) Update

func (r *Repo[TEntity, TKey, TQuery]) Update(ctx context.Context, id TKey, entity *TEntity, p query.Select) error

func (*Repo[TEntity, TKey, TQuery]) Upsert

func (r *Repo[TEntity, TKey, TQuery]) Upsert(ctx context.Context, entity *TEntity) error

type UIDBase

type UIDBase struct {
	ID uuid.UUID `gorm:"type:char(36)" json:"id"`
}

func (*UIDBase) BeforeCreate

func (u *UIDBase) BeforeCreate(tx *gorm.DB) error

type UpdateAssociation

type UpdateAssociation[TEntity any] interface {
	UpdateAssociation(ctx context.Context, entity *TEntity) error
}

Jump to

Keyboard shortcuts

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