gormx

package
v0.0.39 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Reset       = "\033[0m"
	Red         = "\033[31m"
	Green       = "\033[32m"
	Yellow      = "\033[33m"
	Blue        = "\033[34m"
	Magenta     = "\033[35m"
	Cyan        = "\033[36m"
	White       = "\033[37m"
	BlueBold    = "\033[34;1m"
	MagentaBold = "\033[35;1m"
	RedBold     = "\033[31;1m"
	YellowBold  = "\033[33;1m"
)

Colors

Variables

View Source
var (
	DBType_name = map[int32]string{
		0: "UNKNOWN",
		1: "mysql",
		2: "postgres",
		3: "sqlite",
		4: "sqlserver",
	}
	DBType_value = map[string]int32{
		"UNKNOWN":   0,
		"mysql":     1,
		"postgres":  2,
		"sqlite":    3,
		"sqlserver": 4,
	}
)

Enum value maps for DBType.

View Source
var File_store_gormx_conf_proto protoreflect.FileDescriptor

Functions

func ErrDryRunModeUnsupported

func ErrDryRunModeUnsupported(err error) error

ErrDryRunModeUnsupported dry run mode unsupported

func ErrEmptySlice

func ErrEmptySlice(err error) error

ErrEmptySlice empty slice found

func ErrInvalidDB

func ErrInvalidDB(err error) error

ErrInvalidDB invalid db

func ErrInvalidData

func ErrInvalidData(err error) error

ErrInvalidData unsupported data

func ErrInvalidField

func ErrInvalidField(err error) error

ErrInvalidField invalid field

func ErrInvalidTransaction

func ErrInvalidTransaction(err error) error

func ErrInvalidValue

func ErrInvalidValue(err error) error

ErrInvalidValue invalid value

func ErrInvalidValueOfLength

func ErrInvalidValueOfLength(err error) error

ErrInvalidValueOfLength invalid values do not match length

func ErrMissingWhereClause

func ErrMissingWhereClause(err error) error

ErrMissingWhereClause missing where clause

func ErrModelValueRequired

func ErrModelValueRequired(err error) error

ErrModelValueRequired model value required

func ErrNotImplemented

func ErrNotImplemented(err error) error

ErrNotImplemented not implemented

func ErrPrimaryKeyRequired

func ErrPrimaryKeyRequired(err error) error

ErrPrimaryKeyRequired primary keys required

func ErrRegistered

func ErrRegistered(err error) error

ErrRegistered registered

func ErrUnsupportedDriver

func ErrUnsupportedDriver(err error) error

ErrUnsupportedDriver unsupported driver

func ErrUnsupportedRelation

func ErrUnsupportedRelation(err error) error

ErrUnsupportedRelation unsupported relations

func GormErrRecordNotFound

func GormErrRecordNotFound(err error) error

GormErrRecordNotFound 找不到记录

func IsErrInvalidTransaction

func IsErrInvalidTransaction(err error) bool

func IsGormErrRecordNotFound

func IsGormErrRecordNotFound(err error) bool

func NewGormError added in v0.0.29

func NewGormError() gorm.Plugin

func NewGormTracer added in v0.0.27

func NewGormTracer() gorm.Plugin

func NewLogger

func NewLogger(config *LoggerConf, core zapcore.Core) logger.Interface

func WrapGormError

func WrapGormError(err error) error

WrapGormError 转换错误

Types

type Conf

type Conf struct {
	Driver          DBType               `protobuf:"varint,1,opt,name=driver,proto3,enum=store.gormx.DBType" json:"driver,omitempty"`
	Source          string               `protobuf:"bytes,2,opt,name=source,proto3" json:"source,omitempty"`
	MaxOpenConns    int32                `protobuf:"varint,4,opt,name=maxOpenConns,proto3" json:"maxOpenConns,omitempty"`
	MaxIdleConns    int32                `protobuf:"varint,5,opt,name=maxIdleConns,proto3" json:"maxIdleConns,omitempty"`
	ConnMaxLifetime *durationpb.Duration `protobuf:"bytes,6,opt,name=connMaxLifetime,proto3" json:"connMaxLifetime,omitempty"`
	Logger          *LoggerConf          `protobuf:"bytes,7,opt,name=logger,proto3" json:"logger,omitempty"`
	// contains filtered or unexported fields
}

func (*Conf) Descriptor deprecated

func (*Conf) Descriptor() ([]byte, []int)

Deprecated: Use Conf.ProtoReflect.Descriptor instead.

func (*Conf) GetConnMaxLifetime added in v0.0.25

func (x *Conf) GetConnMaxLifetime() *durationpb.Duration

func (*Conf) GetDriver

func (x *Conf) GetDriver() DBType

func (*Conf) GetLogger added in v0.0.34

func (x *Conf) GetLogger() *LoggerConf

func (*Conf) GetMaxIdleConns added in v0.0.25

func (x *Conf) GetMaxIdleConns() int32

func (*Conf) GetMaxOpenConns added in v0.0.25

func (x *Conf) GetMaxOpenConns() int32

func (*Conf) GetSource

func (x *Conf) GetSource() string

func (*Conf) ProtoMessage

func (*Conf) ProtoMessage()

func (*Conf) ProtoReflect

func (x *Conf) ProtoReflect() protoreflect.Message

func (*Conf) Reset

func (x *Conf) Reset()

func (*Conf) String

func (x *Conf) String() string

func (*Conf) Validate

func (m *Conf) Validate() error

Validate checks the field values on Conf with the rules defined in the proto definition for this message. If any rules are violated, the first error encountered is returned, or nil if there are no violations.

func (*Conf) ValidateAll added in v0.0.8

func (m *Conf) ValidateAll() error

ValidateAll checks the field values on Conf with the rules defined in the proto definition for this message. If any rules are violated, the result is a list of violation errors wrapped in ConfMultiError, or nil if none found.

type ConfMultiError added in v0.0.8

type ConfMultiError []error

ConfMultiError is an error wrapping multiple validation errors returned by Conf.ValidateAll() if the designated constraints aren't met.

func (ConfMultiError) AllErrors added in v0.0.8

func (m ConfMultiError) AllErrors() []error

AllErrors returns a list of validation violation errors.

func (ConfMultiError) Error added in v0.0.8

func (m ConfMultiError) Error() string

Error returns a concatenation of all the error messages it wraps.

type ConfValidationError

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

ConfValidationError is the validation error returned by Conf.Validate if the designated constraints aren't met.

func (ConfValidationError) Cause

func (e ConfValidationError) Cause() error

Cause function returns cause value.

func (ConfValidationError) Error

func (e ConfValidationError) Error() string

Error satisfies the builtin error interface

func (ConfValidationError) ErrorName

func (e ConfValidationError) ErrorName() string

ErrorName returns error name.

func (ConfValidationError) Field

func (e ConfValidationError) Field() string

Field function returns field value.

func (ConfValidationError) Key

func (e ConfValidationError) Key() bool

Key function returns key value.

func (ConfValidationError) Reason

func (e ConfValidationError) Reason() string

Reason function returns reason value.

type DB

type DB = gorm.DB

func MustNew

func MustNew(c *Conf) *DB

func New

func New(c *Conf) (*DB, error)

type DBType added in v0.0.21

type DBType int32

dbMySQL Gorm Drivers mysql || postgres || sqlite || sqlserver

const (
	DBType_UNKNOWN   DBType = 0
	DBType_mysql     DBType = 1
	DBType_postgres  DBType = 2
	DBType_sqlite    DBType = 3
	DBType_sqlserver DBType = 4
)

func (DBType) Descriptor added in v0.0.25

func (DBType) Descriptor() protoreflect.EnumDescriptor

func (DBType) Enum added in v0.0.25

func (x DBType) Enum() *DBType

func (DBType) EnumDescriptor deprecated added in v0.0.25

func (DBType) EnumDescriptor() ([]byte, []int)

Deprecated: Use DBType.Descriptor instead.

func (DBType) Number added in v0.0.25

func (x DBType) Number() protoreflect.EnumNumber

func (DBType) String added in v0.0.25

func (x DBType) String() string

func (DBType) Type added in v0.0.25

func (DBType) Type() protoreflect.EnumType

type GormError added in v0.0.29

type GormError struct{}

func (*GormError) Initialize added in v0.0.29

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

func (*GormError) Name added in v0.0.29

func (p *GormError) Name() string

type GormTracer added in v0.0.27

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

func (*GormTracer) Initialize added in v0.0.27

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

func (*GormTracer) Name added in v0.0.27

func (p *GormTracer) Name() string

type Logger

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

func (*Logger) Error

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

Error print error messages

func (*Logger) Info

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

Info print info

func (*Logger) LogMode

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

LogMode log mode

func (*Logger) Trace

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

Trace print sql message

func (*Logger) Warn

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

Warn print warn messages

type LoggerConf added in v0.0.34

type LoggerConf struct {
	SlowThreshold             *durationpb.Duration `protobuf:"bytes,1,opt,name=slowThreshold,proto3" json:"slowThreshold,omitempty"`
	Colorful                  bool                 `protobuf:"varint,2,opt,name=colorful,proto3" json:"colorful,omitempty"`
	IgnoreRecordNotFoundError bool                 `protobuf:"varint,3,opt,name=ignoreRecordNotFoundError,proto3" json:"ignoreRecordNotFoundError,omitempty"`
	ParameterizedQueries      bool                 `protobuf:"varint,4,opt,name=parameterizedQueries,proto3" json:"parameterizedQueries,omitempty"`
	LogLevel                  int32                `protobuf:"varint,5,opt,name=logLevel,proto3" json:"logLevel,omitempty"`
	// contains filtered or unexported fields
}

func (*LoggerConf) Descriptor deprecated added in v0.0.34

func (*LoggerConf) Descriptor() ([]byte, []int)

Deprecated: Use LoggerConf.ProtoReflect.Descriptor instead.

func (*LoggerConf) GetColorful added in v0.0.34

func (x *LoggerConf) GetColorful() bool

func (*LoggerConf) GetIgnoreRecordNotFoundError added in v0.0.34

func (x *LoggerConf) GetIgnoreRecordNotFoundError() bool

func (*LoggerConf) GetLogLevel added in v0.0.34

func (x *LoggerConf) GetLogLevel() int32

func (*LoggerConf) GetParameterizedQueries added in v0.0.34

func (x *LoggerConf) GetParameterizedQueries() bool

func (*LoggerConf) GetSlowThreshold added in v0.0.34

func (x *LoggerConf) GetSlowThreshold() *durationpb.Duration

func (*LoggerConf) ProtoMessage added in v0.0.34

func (*LoggerConf) ProtoMessage()

func (*LoggerConf) ProtoReflect added in v0.0.34

func (x *LoggerConf) ProtoReflect() protoreflect.Message

func (*LoggerConf) Reset added in v0.0.34

func (x *LoggerConf) Reset()

func (*LoggerConf) String added in v0.0.34

func (x *LoggerConf) String() string

func (*LoggerConf) Validate added in v0.0.34

func (m *LoggerConf) Validate() error

Validate checks the field values on LoggerConf with the rules defined in the proto definition for this message. If any rules are violated, the first error encountered is returned, or nil if there are no violations.

func (*LoggerConf) ValidateAll added in v0.0.34

func (m *LoggerConf) ValidateAll() error

ValidateAll checks the field values on LoggerConf with the rules defined in the proto definition for this message. If any rules are violated, the result is a list of violation errors wrapped in LoggerConfMultiError, or nil if none found.

type LoggerConfMultiError added in v0.0.34

type LoggerConfMultiError []error

LoggerConfMultiError is an error wrapping multiple validation errors returned by LoggerConf.ValidateAll() if the designated constraints aren't met.

func (LoggerConfMultiError) AllErrors added in v0.0.34

func (m LoggerConfMultiError) AllErrors() []error

AllErrors returns a list of validation violation errors.

func (LoggerConfMultiError) Error added in v0.0.34

func (m LoggerConfMultiError) Error() string

Error returns a concatenation of all the error messages it wraps.

type LoggerConfValidationError added in v0.0.34

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

LoggerConfValidationError is the validation error returned by LoggerConf.Validate if the designated constraints aren't met.

func (LoggerConfValidationError) Cause added in v0.0.34

func (e LoggerConfValidationError) Cause() error

Cause function returns cause value.

func (LoggerConfValidationError) Error added in v0.0.34

Error satisfies the builtin error interface

func (LoggerConfValidationError) ErrorName added in v0.0.34

func (e LoggerConfValidationError) ErrorName() string

ErrorName returns error name.

func (LoggerConfValidationError) Field added in v0.0.34

Field function returns field value.

func (LoggerConfValidationError) Key added in v0.0.34

Key function returns key value.

func (LoggerConfValidationError) Reason added in v0.0.34

func (e LoggerConfValidationError) Reason() string

Reason function returns reason value.

Jump to

Keyboard shortcuts

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