database

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2022 License: MIT Imports: 9 Imported by: 0

README

database

build tags with follow:

nomysql: disable mysql < default enable mysql >
nopostgres: disable postgres < default enable postgres > sqlite3: enable sqlite3 < default disable sqlite3 >

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close(db *gorm.DB) error

func New

func New(c Config, config *gorm.Config, dialectorNews ...func(c Config) gorm.Dialector) (*gorm.DB, error)

func SetDBLogger

func SetDBLogger(db *gorm.DB, l logger.Interface)

SetDBLogger set db logger

Types

type Config

type Config struct {
	// mysql sqlite3 postgres and custom
	Dialect string `yaml:"dialect" json:"dialect"`
	// dsn
	Dsn string `yaml:"dsn" json:"dsn"`
	// MaxIdleConn sets the maximum number of open connections to the database.
	// If n <= 0, then there is no limit on the number of open connections.
	// The default is 0 (unlimited).
	MaxIdleConn int `yaml:"maxIdleConn" json:"maxIdleConn"`
	// MaxOpenConn sets the maximum number of open connections to the database.
	// If n <= 0, then there is no limit on the number of open connections.
	// The default is 0 (unlimited).
	MaxOpenConn int `yaml:"maxOpenConn" json:"maxOpenConn"`
	// MaxLifetime sets the maximum amount of time a connection may be reused.
	// If d <= 0, connections are not closed due to a connection's age.
	MaxLifetime time.Duration `yaml:"maxLifetime" json:"maxLifetime"`
	// MaxIdleTime sets the maximum amount of time a connection may be idle.
	// If d <= 0, connections are not closed due to a connection's idle time.
	MaxIdleTime time.Duration `yaml:"maxIdleTime" json:"maxIdleTime"`
	// EnableLog enabled log flag  use by user
	EnableLog bool `yaml:"enableLog" json:"enableLog"`
}

Config 数据库配置

Jump to

Keyboard shortcuts

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