gorm

package
v1.10.5 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: MIT, Apache-2.0 Imports: 28 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

func ByName added in v1.10.0

func ByName(name string) clause.Expression

func ByPrimary added in v1.10.0

func ByPrimary(id any) clause.Expression

func ByPrimaryKey added in v1.10.0

func ByPrimaryKey(v any) clause.Expression

func ConditionsBy added in v1.10.0

func ConditionsBy(param any) []clause.Expression

func Delete

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

func DeleteByPrimary added in v1.10.0

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

func Exists

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

func ExistsByColumn

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

func ExistsByColumnWithDeletedAt

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

func ExistsByFilterExprs

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

func ExistsByQuery

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

根据查询语句查询数据是否存在

func ExistsBySQL

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

func FindList added in v1.10.0

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

func Generator added in v1.10.0

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

func GetByPrimary added in v1.10.0

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

func New added in v1.10.0

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

func NewCondition added in v1.10.0

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

func NotConditionBy added in v1.10.0

func NotConditionBy(param any) clause.Expression

func OrConditionBy added in v1.10.0

func OrConditionBy(param any) clause.Expression

func PaginationExpr added in v1.10.0

func PaginationExpr(pageNo, pageSize uint32) clause.Expression

func SetTranceId added in v1.10.0

func SetTranceId(ctx context.Context, traceId string) context.Context

func SingleSortExpr added in v1.10.0

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

func SortExpr added in v1.10.0

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

func TableName

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

func TraceId added in v1.10.0

func TraceId(ctx context.Context) string

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)

func (Between) NegationBuild added in v1.10.0

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

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 Collector added in v1.10.2

type Collector interface {
	Init(prefix string, db *gorm.DB, meter metric.Meter) error
	Close(context.Context) error
}

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 {
	Init(meter metric.Meter) error
	Record(*RecordContext)
}

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

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

func (FilterExprs) Condition added in v1.10.0

func (f FilterExprs) Condition() clause.Expression

func (FilterExprs) Conditions added in v1.10.0

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

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)

func (IsNotNull) NegationBuild added in v1.10.0

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

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)

func (IsNull) NegationBuild added in v1.10.0

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

type JSONSerializer added in v1.10.0

type JSONSerializer struct {
}

JSONSerializer json序列化器

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 方法

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 方法

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

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

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

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

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

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

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

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

func (Location) GormValue added in v1.10.0

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

func (*Location) Scan added in v1.10.0

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

Scan 方法实现了 sql.Scanner 接口

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 print sql message 只有这里的context不是background,看了代码,也没用

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)

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)

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

func (*OTelPlugin) Close added in v1.10.2

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

func (*OTelPlugin) Initialize added in v1.10.2

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

func (*OTelPlugin) Name added in v1.10.2

func (p *OTelPlugin) Name() string

type Option added in v1.10.2

type Option func(*OTelPlugin)

func WithAttributes added in v1.10.2

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

func WithCustomMetrics added in v1.10.2

func WithCustomMetrics(metrics ...CustomMetric) Option

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

func (*Pagination) Clause added in v1.10.0

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

type PaginationEmbedded added in v1.10.0

type PaginationEmbedded sqlx.PaginationEmbedded

func (*PaginationEmbedded) ToPagination added in v1.10.0

func (req *PaginationEmbedded) ToPagination() *Pagination

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

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

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

type StringArraySerializer added in v1.10.0

type StringArraySerializer struct {
}

StringArraySerializer array序列化器

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 方法

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 方法

Jump to

Keyboard shortcuts

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