gorm

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT, Apache-2.0 Imports: 34 Imported by: 4

Documentation

Index

Constants

View Source
const ScopeName = "github.com/hopeio/gox/database/sql/gorm"

Variables

This section is empty.

Functions

func AndConditionBy added in v1.10.0

func AndConditionBy(param any) clause.Expression

AndConditionBy returns the result.

func ByName added in v1.10.0

func ByName(name string) clause.Expression

ByName returns the result.

func ByPrimary added in v1.10.0

func ByPrimary(id any) clause.Expression

ByPrimary returns the result.

func ByPrimaryKey added in v1.10.0

func ByPrimaryKey(v any) clause.Expression

ByPrimaryKey returns the result.

func ConditionsBy added in v1.10.0

func ConditionsBy(param any) []clause.Expression

ConditionsBy returns the result.

func Delete

func Delete(db *gorm.DB, tableName string, column string, value any) error

Delete removes or resets state.

func DeleteByPrimary added in v1.10.0

func DeleteByPrimary(db *gorm.DB, tableName string, primary any) error

DeleteByPrimary removes or resets state.

func Exists

func Exists(db *gorm.DB, tableName, column string, value any, withDeletedAt bool) (bool, error)

Exists performs the operation.

func ExistsByColumn

func ExistsByColumn(db *gorm.DB, tableName, column string, value any) (bool, error)

ExistsByColumn performs the operation.

func ExistsByColumnWithDeletedAt

func ExistsByColumnWithDeletedAt(db *gorm.DB, tableName, column string, value any) (bool, error)

ExistsByColumnWithDeletedAt performs the operation.

func ExistsByFilterExprs

func ExistsByFilterExprs(db *gorm.DB, tableName string, filters sqlx.FilterExprs) (bool, error)

ExistsByFilterExprs performs the operation.

func ExistsByQuery

func ExistsByQuery(db *gorm.DB, qsql string, value ...any) (bool, error)

ExistsByQuery performs the operation.

func ExistsBySQL

func ExistsBySQL(db *gorm.DB, sql string, value ...any) (bool, error)

ExistsBySQL performs the operation.

func FindList added in v1.10.0

func FindList[T any](db *gorm.DB, list *sqlx.List) ([]T, int64, error)

FindList performs the operation.

func Generator added in v1.10.0

func Generator(db *gorm.DB, outPath, modelPkgPath string, tables ...string) error

Generator performs the operation.

func GetByPrimary added in v1.10.0

func GetByPrimary[T any](db *gorm.DB, primary any) (*T, error)

GetByPrimary returns the value.

func New added in v1.10.0

func New(loger *zap.Logger, conf *logger.Config) logger.Interface

New creates a new instance.

func NewCondition added in v1.10.0

func NewCondition(field string, op sqlx.ConditionOperation, args any) clause.Expression

NewCondition creates and returns a new instance.

func NotConditionBy added in v1.10.0

func NotConditionBy(param any) clause.Expression

NotConditionBy returns the result.

func OrConditionBy added in v1.10.0

func OrConditionBy(param any) clause.Expression

OrConditionBy returns the result.

func PaginationExpr added in v1.10.0

func PaginationExpr(pageNo, pageSize uint32) clause.Expression

PaginationExpr returns the result.

func SingleSortExpr added in v1.10.0

func SingleSortExpr(field string, sortType sqlx.SortType) clause.Expression

SingleSortExpr returns the result.

func SortExpr added in v1.10.0

func SortExpr(expr clause.Expression, sorts ...sqlx.Sort) clause.Expression

SortExpr returns the result.

func TableName

func TableName(tx *gorm.DB, name string) *gorm.DB

TableName returns the result.

Types

type Between added in v1.10.0

type Between struct {
	Column     any
	Begin, End any
}

func (Between) Build added in v1.10.0

func (gt Between) Build(builder clause.Builder)

Build performs the operation.

func (Between) NegationBuild added in v1.10.0

func (gt Between) NegationBuild(builder clause.Builder)

NegationBuild performs the operation.

type Clause added in v1.10.0

type Clause interface {
	Clause() clause.Expression
}

type Clauses added in v1.10.0

type Clauses interface {
	Clauses() []clause.Expression
}

type ConditionExpr added in v1.10.0

type ConditionExpr interface {
	Condition() clause.Expression
}

type ConditionsExpr added in v1.10.0

type ConditionsExpr interface {
	Conditions() []clause.Expression
}

type Config

type Config struct {
	SlowThreshold time.Duration
	Colorful      bool
	LogLevel      zapcore.Level
}

type CustomMetric added in v1.10.2

type CustomMetric interface {
	Record(*RecordContext)
}

type DateSerializer added in v1.11.8

type DateSerializer struct {
}

func (DateSerializer) Scan added in v1.11.8

func (DateSerializer) Scan(ctx context.Context, field *schema.Field, dst reflect.Value, dbValue interface{}) (err error)

Scan implements serializer interface

func (DateSerializer) Value added in v1.11.8

func (DateSerializer) Value(ctx context.Context, field *schema.Field, dst reflect.Value, fieldValue interface{}) (result interface{}, err error)

Value implements serializer interface

type FilterExpr added in v1.10.0

type FilterExpr sqlx.FilterExpr

func (*FilterExpr) Condition added in v1.10.0

func (f *FilterExpr) Condition() clause.Expression

Condition returns the result.

type FilterExprs added in v1.10.0

type FilterExprs sqlx.FilterExprs

func (FilterExprs) Apply added in v1.10.0

func (f FilterExprs) Apply(db *gorm.DB) *gorm.DB

Apply returns the result.

func (FilterExprs) Condition added in v1.10.0

func (f FilterExprs) Condition() clause.Expression

Condition returns the result.

func (FilterExprs) Conditions added in v1.10.0

func (f FilterExprs) Conditions() []clause.Expression

Conditions returns the result.

type GlobalMetrics added in v1.11.0

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

func GlobalGormMetrics added in v1.11.0

func GlobalGormMetrics() *GlobalMetrics

GlobalGormMetrics returns the result.

func (*GlobalMetrics) Register added in v1.11.0

func (m *GlobalMetrics) Register(db *gorm.DB, attrs ...attribute.KeyValue) error

Register performs the operation.

type IsNotNull added in v1.10.0

type IsNotNull IsNull

func (IsNotNull) Build added in v1.10.0

func (inn IsNotNull) Build(builder clause.Builder)

Build performs the operation.

func (IsNotNull) NegationBuild added in v1.10.0

func (inn IsNotNull) NegationBuild(builder clause.Builder)

NegationBuild performs the operation.

type IsNull added in v1.10.0

type IsNull struct {
	Column any
}

func (IsNull) Build added in v1.10.0

func (in IsNull) Build(builder clause.Builder)

Build performs the operation.

func (IsNull) NegationBuild added in v1.10.0

func (in IsNull) NegationBuild(builder clause.Builder)

NegationBuild performs the operation.

type JSONSerializer added in v1.10.0

type JSONSerializer struct {
}

JSONSerializer is a JSON serializer

func (JSONSerializer) Scan added in v1.10.0

func (JSONSerializer) Scan(ctx context.Context, field *schema.Field, dst reflect.Value, dbValue interface{}) (err error)

Scan performs the operation.

func (JSONSerializer) Value added in v1.10.0

func (JSONSerializer) Value(ctx context.Context, field *schema.Field, dst reflect.Value, fieldValue interface{}) (interface{}, error)

Value returns the value.

type Json added in v1.10.0

type Json[T any] sqlx.Json[T]

func (*Json[T]) GormDBDataType added in v1.10.0

func (*Json[T]) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType returns the result.

func (*Json[T]) GormValue added in v1.10.0

func (j *Json[T]) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

GormValue returns the result.

func (*Json[T]) Scan added in v1.10.0

func (j *Json[T]) Scan(v any) error

Scan performs the operation.

func (*Json[T]) Value added in v1.10.0

func (j *Json[T]) Value() (driver.Value, error)

Value returns the value.

type Limit added in v1.10.0

type Limit struct {
	Limit  uint32
	Offset uint64
}

Limit limit clause

func (Limit) Build added in v1.10.0

func (limit Limit) Build(builder clause.Builder)

Build build where clause

func (Limit) MergeClause added in v1.10.0

func (limit Limit) MergeClause(clause *clause.Clause)

MergeClause merge order by clauses

func (Limit) Name added in v1.10.0

func (limit Limit) Name() string

Name where clause name

type Location added in v1.10.0

type Location struct {
	X, Y float64
}

func (Location) GormDataType added in v1.10.0

func (loc Location) GormDataType() string

GormDataType returns the result.

func (Location) GormValue added in v1.10.0

func (loc Location) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

GormValue returns the result.

func (*Location) Scan added in v1.10.0

func (loc *Location) Scan(v interface{}) error

Scan performs the operation.

type Logger added in v1.10.0

type Logger struct {
	*zap.Logger
	*logger.Config
}

func (*Logger) Error added in v1.10.0

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

Error print error messages

func (*Logger) Info added in v1.10.0

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

Info print info

func (*Logger) LogMode added in v1.10.0

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

LogMode log mode

func (*Logger) Trace added in v1.10.0

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

Trace performs the operation.

func (*Logger) Warn added in v1.10.0

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

Warn print warn messages

type Not added in v1.10.0

type Not struct {
	Expr clause.NegationExpressionBuilder
}

func (Not) Build added in v1.10.0

func (n Not) Build(builder clause.Builder)

Build performs the operation.

type NotLike added in v1.10.0

type NotLike clause.Neq

func (NotLike) Build added in v1.10.0

func (nl NotLike) Build(builder clause.Builder)

Build performs the operation.

type OTelPlugin added in v1.10.2

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

func NewOTelPlugin added in v1.10.2

func NewOTelPlugin(opts ...Option) *OTelPlugin

NewOTelPlugin creates and returns a new instance.

func (*OTelPlugin) Close added in v1.10.2

func (p *OTelPlugin) Close(ctx context.Context) error

Close closes and releases resources.

func (*OTelPlugin) Initialize added in v1.10.2

func (p *OTelPlugin) Initialize(db *gorm.DB) error

Initialize performs the operation.

func (*OTelPlugin) Name added in v1.10.2

func (p *OTelPlugin) Name() string

Name returns the result.

type Option added in v1.10.2

type Option func(*OTelPlugin)

func WithAttributes added in v1.10.2

func WithAttributes(attrs ...attribute.KeyValue) Option

WithAttributes updates or inserts a value.

func WithCustomMetrics added in v1.10.2

func WithCustomMetrics(metrics ...CustomMetric) Option

WithCustomMetrics updates or inserts a value.

func WithDBSystem added in v1.12.0

func WithDBSystem(name string) Option

WithDBSystem updates or inserts a value.

func WithQueryFormatter added in v1.12.0

func WithQueryFormatter(fn func(query string) string) Option

WithQueryFormatter updates or inserts a value.

func WithRecordStackTrace added in v1.12.0

func WithRecordStackTrace() Option

WithRecordStackTrace updates or inserts a value.

func WithServerAddressProvider added in v1.12.0

func WithServerAddressProvider(fn func(dialector gorm.Dialector) string) Option

WithServerAddressProvider updates or inserts a value.

func WithTracerProvider added in v1.12.0

func WithTracerProvider(provider trace.TracerProvider) Option

WithTracerProvider updates or inserts a value.

func WithoutMetrics added in v1.12.0

func WithoutMetrics() Option

WithoutMetrics updates or inserts a value.

func WithoutQueryVariables added in v1.12.0

func WithoutQueryVariables() Option

WithoutQueryVariables updates or inserts a value.

type Pagination added in v1.10.0

type Pagination sqlx.Pagination

func (*Pagination) Apply added in v1.10.0

func (req *Pagination) Apply(db *gorm.DB) *gorm.DB

Apply returns the result.

func (*Pagination) Clause added in v1.10.0

func (req *Pagination) Clause() clause.Expression

Clause returns the result.

type PaginationEmbedded added in v1.10.0

type PaginationEmbedded sqlx.PaginationEmbedded

func (*PaginationEmbedded) ToPagination added in v1.10.0

func (req *PaginationEmbedded) ToPagination() *Pagination

ToPagination converts the value.

type Range added in v1.10.0

type Range[T any] sqlx.Range[T]

func (*Range[T]) Condition added in v1.10.0

func (req *Range[T]) Condition() clause.Expression

Condition returns the result.

type RecordContext added in v1.10.2

type RecordContext struct {
	Ctx        context.Context
	Operation  string
	DB         *gorm.DB
	Attrs      []attribute.KeyValue
	BaseAttrs  []attribute.KeyValue
	ErrorType  string
	Success    bool
	StartTime  time.Time
	DurationMs float64
}

type Sort added in v1.10.0

type Sort sqlx.Sort

func (*Sort) Clause added in v1.10.0

func (o *Sort) Clause() clause.Expression

Clause returns the result.

type Sorts added in v1.10.0

type Sorts []sqlx.Sort

func (Sorts) Clause added in v1.10.0

func (o Sorts) Clause() clause.Expression

Clause returns the result.

type StringArraySerializer added in v1.10.0

type StringArraySerializer struct {
}

StringArraySerializer is an array serializer

func (StringArraySerializer) Scan added in v1.10.0

func (StringArraySerializer) Scan(ctx context.Context, field *schema.Field, dst reflect.Value,
	dbValue any) (err error)

Scan returns the result.

func (StringArraySerializer) Value added in v1.10.0

func (StringArraySerializer) Value(ctx context.Context, field *schema.Field, dst reflect.Value, fieldValue any) (any, error)

Value returns the value.

type UnixMilliTimeSerializer added in v1.11.8

type UnixMilliTimeSerializer struct {
}

func (UnixMilliTimeSerializer) Scan added in v1.11.8

func (UnixMilliTimeSerializer) Scan(ctx context.Context, field *schema.Field, dst reflect.Value, dbValue interface{}) (err error)

Scan implements serializer interface

func (UnixMilliTimeSerializer) Value added in v1.11.8

func (UnixMilliTimeSerializer) Value(ctx context.Context, field *schema.Field, dst reflect.Value, fieldValue interface{}) (result interface{}, err error)

Value implements serializer interface

Jump to

Keyboard shortcuts

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