gorm

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(c DataConf, ctxlog *log.Helper) (*gorm.DB, error)

New 创建 gorm 连接

func NewWithOptions

func NewWithOptions(c DataConf, opts ...Option) (*gorm.DB, error)

func WithOmitVariablesFromTrace

func WithOmitVariablesFromTrace(ctx context.Context) context.Context

Types

type Config

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

Config 自定义 Gorm 配置项

type DataConf

type DataConf interface {
	GetDriver() string
	GetSource() string
	// GetDebug ... alias IsDebug()
	GetDebug() bool
}

type GormTracingOption

type GormTracingOption interface {
	// contains filtered or unexported methods
}

GormTracingOption is used to configure the client.

func WithAlwaysOmitVariables

func WithAlwaysOmitVariables() GormTracingOption

WithAlwaysOmitVariables makes the plugin always omit variable values from traces.

func WithDBName

func WithDBName(name string) GormTracingOption

WithDBName specified the database name to be used in span names since its not possible to extract this information from gorm

func WithTracerProvider

func WithTracerProvider(provider oteltrace.TracerProvider) GormTracingOption

WithTracerProvider specifies a tracer provider to use for creating a tracer. If none is specified, the global provider is used.

type Logger

type Logger struct {
	SlowThreshold         time.Duration
	SourceField           string
	SkipCallerLookup      bool
	SkipErrRecordNotFound bool
	// contains filtered or unexported fields
}

func NewGormLogger

func NewGormLogger(dbLog *log.Helper, hasDebug bool) *Logger

func (*Logger) Error

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

func (*Logger) Info

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

func (*Logger) LogMode

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

func (*Logger) Trace

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

func (*Logger) Warn

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

type Option

type Option func(*Config)

func WithDriver

func WithDriver(driver gorm.Dialector) Option

WithDriver set gorm-driver.

func WithLogger

func WithLogger(log *log.Helper, hasDebug bool) Option

WithLogger set gorm-logger and has debug logger writer..

func WithTracing

func WithTracing() Option

WithTracing set gorm-tracing. used for opentracing.

type OtelPlugin

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

func NewPlugin

func NewPlugin(opts ...GormTracingOption) *OtelPlugin

NewPlugin initialize a new gorm.DB plugin that traces queries You may pass optional Options to the function

func (*OtelPlugin) Initialize

func (op *OtelPlugin) Initialize(db *gorm.DB) error

func (*OtelPlugin) Name

func (op *OtelPlugin) Name() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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