database

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: MIT Imports: 10 Imported by: 0

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) (*gorm.DB, error)

func NewSqlite3 added in v0.4.0

func NewSqlite3(string) gorm.Dialector

func SetDBLogger

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

SetDBLogger set db logger

Types

type Config

type Config struct {
	// EnableLog enabled log flag  use by user
	EnableLog bool `yaml:"enableLog" json:"enableLog"`
	// mysql sqlite3 postgres
	Dialect string       `yaml:"dialect" json:"dialect"`
	Source  SourceServe  `yaml:"source" json:"source"`
	Replica ReplicaServe `yaml:"replica" json:"replica"`
}

type Node added in v0.4.0

type Node struct {
	// dsn
	Dsn string `yaml:"dsn" json:"dsn"`
}

Node 数据库配置

type ReplicaServe added in v0.4.0

type ReplicaServe struct {
	// 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"`
	Node        []Node        `yaml:"node" json:"node"`
}

type SourceServe added in v0.4.0

type SourceServe struct {
	// 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"`
	Node        Node          `yaml:"node" json:"node"`
}

Jump to

Keyboard shortcuts

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