gorm

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: Apache-2.0 Imports: 25 Imported by: 0

README

gorm

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// IsRecordNotFoundError ...
	IsRecordNotFoundError = gorm.IsRecordNotFoundError

	// ErrRecordNotFound returns a "record not found error". Occurs only when attempting to query the database with a struct; querying with a slice won't return this error
	ErrRecordNotFound = gorm.ErrRecordNotFound
	// ErrInvalidSQL occurs when you attempt a query with invalid SQL
	ErrInvalidSQL = gorm.ErrInvalidSQL
	// ErrInvalidTransaction occurs when you are trying to `Commit` or `Rollback`
	ErrInvalidTransaction = gorm.ErrInvalidTransaction
	// ErrCantStartTransaction can't start transaction when you are trying to start one with `Begin`
	ErrCantStartTransaction = gorm.ErrCantStartTransaction
	// ErrUnaddressable unaddressable value
	ErrUnaddressable = gorm.ErrUnaddressable
)

Functions

func Configs

func Configs() map[string]interface{}

Configs

func Range

func Range(fn func(name string, db *DB) bool)

Range 遍历所有实例

func Stats

func Stats() (stats map[string]interface{})

Stats

Types

type Association

type Association = gorm.Association

Association ...

type Callback

type Callback = gorm.Callback

Callback alias of gorm.Callback

type CallbackProcessor

type CallbackProcessor = gorm.CallbackProcessor

CallbackProcessor alias of gorm.CallbackProcessor

type Config

type Config struct {
	Name string
	// DSN地址: mysql://root:secret@tcp(127.0.0.1:3307)/mysql?timeout=20s&readTimeout=20s
	DSN string `json:"dsn" toml:"dsn"`
	// Debug开关
	Debug bool `json:"debug" toml:"debug"`
	// 最大空闲连接数
	MaxIdleConns int `json:"maxIdleConns" toml:"maxIdleConns"`
	// 最大活动连接数
	MaxOpenConns int `json:"maxOpenConns" toml:"maxOpenConns"`
	// 连接的最大存活时间
	ConnMaxLifetime time.Duration `json:"connMaxLifetime" toml:"connMaxLifetime"`
	// 创建连接的错误级别,=panic时,如果创建失败,立即panic
	OnDialError string `json:"level" toml:"level"`
	// 慢日志阈值
	SlowThreshold time.Duration `json:"slowThreshold" toml:"slowThreshold"`
	// 拨超时时间
	DialTimeout time.Duration `json:"dialTimeout" toml:"dialTimeout"`
	// 关闭指标采集
	DisableMetric bool `json:"disableMetric" toml:"disableMetric"`
	// 关闭链路追踪
	DisableTrace bool `json:"disableTrace" toml:"disableTrace"`

	// 记录错误sql时,是否打印包含参数的完整sql语句
	// select * from aid = ?;
	// select * from aid = 288016;
	DetailSQL bool `json:"detailSql" toml:"detailSql"`
	// contains filtered or unexported fields
}

config options

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig 返回默认配置

func RawConfig

func RawConfig(key string) *Config

RawConfig 传入mapstructure格式的配置 example: RawConfig("jupiter.mysql.stt_config")

func StdConfig

func StdConfig(name string) *Config

StdConfig 标准配置,规范配置文件头

func (*Config) Build

func (config *Config) Build() *DB

Build ...

func (*Config) WithInterceptor

func (config *Config) WithInterceptor(intes ...Interceptor) *Config

WithInterceptor ...

func (*Config) WithLogger

func (config *Config) WithLogger(log *xlog.Logger) *Config

WithLogger ...

type DB

type DB = gorm.DB

DB ...

func Open

func Open(dialect string, options *Config) (*DB, error)

Open ...

func WithContext

func WithContext(ctx context.Context, db *DB) *DB

WithContext ...

type DSN

type DSN struct {
	User     string            // Username
	Password string            // Password (requires User)
	Net      string            // Network type
	Addr     string            // Network address (requires Net)
	DBName   string            // Database name
	Params   map[string]string // Connection parameters
}

DSN ...

func ParseDSN

func ParseDSN(dsn string) (cfg *DSN, err error)

ParseDSN parses the DSN string to a NodeConfig

type Dialect

type Dialect = gorm.Dialect

Dialect alias of gorm.Dialect

type Errors

type Errors = gorm.Errors

Errors ...

type Field

type Field = gorm.Field

Field ...

type Handler

type Handler func(*Scope)

Handler ...

type Interceptor

type Interceptor func(*DSN, string, *Config) func(next Handler) Handler

Interceptor ...

type Logger

type Logger = gorm.Logger

logger ...

type Model

type Model = gorm.Model

Model ...

type ModelStruct

type ModelStruct = gorm.ModelStruct

ModelStruct ...

type RowQueryResult

type RowQueryResult = gorm.RowQueryResult

RowQueryResult ...

type RowsQueryResult

type RowsQueryResult = gorm.RowsQueryResult

RowsQueryResult ...

type SQLCommon

type SQLCommon = gorm.SQLCommon

SQLCommon alias of gorm.SQLCommon

type Scope

type Scope = gorm.Scope

Scope ...

type StructField

type StructField = gorm.StructField

FieldStruct ...

Jump to

Keyboard shortcuts

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