gormV2

package
v0.0.0-...-d6ac821 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: 17 Imported by: 0

README

gorm

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// 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
)

Functions

This section is empty.

Types

type Association

type Association = gorm.Association

ModelStruct ... ModelStruct = gorm.ModelStruct Field ... Field = gorm.Field FieldStruct ... StructField = gorm.StructField RowQueryResult ... RowQueryResult = gorm.RowQueryResult RowsQueryResult ... RowsQueryResult = gorm.RowsQueryResult Association ...

type Config

type Config struct {
	// 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 TemplateConfig

func TemplateConfig(name string) *Config

func (*Config) Build

func (config *Config) Build() *DB

Build ...

func (*Config) WithLogger

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

WithLogger ...

type DB

type DB = gorm.DB

SQLCommon alias of gorm.SQLCommon SQLCommon = gorm.SQLCommon Callback alias of gorm.Callback Callback = gorm.Callback CallbackProcessor alias of gorm.CallbackProcessor CallbackProcessor = gorm.CallbackProcessor Dialect alias of gorm.Dialect Dialect = gorm.Dialect Scope ... Scope = gorm.Scope DB ...

func Open

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

Open ...

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 Model

type Model = gorm.Model

Model ...

Jump to

Keyboard shortcuts

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