gorm

package
v0.0.0-...-3205ce4 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultGroupName = "default" // Default group name.
)

Variables

This section is empty.

Functions

func AddConfigNode

func AddConfigNode(group string, node ConfigNode)

AddConfigNode adds one node configuration to configuration of given group.

func AddDefaultConfigGroup

func AddDefaultConfigGroup(nodes ConfigGroup)

AddDefaultConfigGroup adds multiple node configurations to configuration of default group.

func AddDefaultConfigNode

func AddDefaultConfigNode(node ConfigNode)

AddDefaultConfigNode adds one node configuration to configuration of default group.

func GetDefaultGroup

func GetDefaultGroup() string

GetDefaultGroup returns the { name of default configuration.

func Instance

func Instance(name ...string) *gorm.DB

func IsConfigured

func IsConfigured() bool

IsConfigured checks and returns whether the database configured. It returns true if any configuration exists.

func New

func New(group ...string) (db *gorm.DB, err error)

New creates and returns an ORM object with global configurations. The parameter <name> specifies the configuration group name, which is DefaultGroupName in default.

func SetConfig

func SetConfig(config Config)

SetConfig sets the global configuration for package. It will overwrite the old configuration of package.

func SetConfigGroup

func SetConfigGroup(group string, nodes ConfigGroup)

SetConfigGroup sets the configuration for given group.

func SetDefaultGroup

func SetDefaultGroup(name string)

SetDefaultGroup sets the group name for default configuration.

Types

type Config

type Config map[string]ConfigGroup

Config is the configuration management object.

type ConfigGroup

type ConfigGroup []ConfigNode

ConfigGroup is a slice of configuration node for specified named group.

func GetConfig

func GetConfig(group string) ConfigGroup

GetConfig retrieves and returns the configuration of given group.

type ConfigNode

type ConfigNode struct {
	Host                 string        // Host of server, ip or domain like: 127.0.0.1, localhost
	Port                 string        // Port, it's commonly 3306.
	User                 string        // Authentication username.
	Pass                 string        // Authentication password.
	Name                 string        // Default used database name.
	Type                 string        // Database type: mysql, sqlite, mssql, pgsql, oracle.
	Role                 string        // (Optional, "master" in default) Node role, used for master-slave mode: master, slave.
	Debug                bool          // (Optional) Debug mode enables debug information logging and output.
	Prefix               string        // (Optional) Table prefix.
	DryRun               bool          // (Optional) Dry run, which does SELECT but no INSERT/UPDATE/DELETE statements.
	Weight               int           // (Optional) Weight for load balance calculating, it's useless if there's just one node.
	Charset              string        // (Optional, "utf8mb4" in default) Custom charset when operating on database.
	LinkInfo             string        `json:"link"`        // (Optional) Custom link information, when it is used, configuration Host/Port/User/Pass/Name are ignored.
	MaxIdleConnCount     int           `json:"maxidle"`     // (Optional) Max idle connection configuration for underlying connection pool.
	MaxOpenConnCount     int           `json:"maxopen"`     // (Optional) Max open connection configuration for underlying connection pool.
	MaxConnLifetime      time.Duration `json:"maxlifetime"` // (Optional) Max connection TTL configuration for underlying connection pool.
	CreatedAt            string        // (Optional) The filed name of table for automatic-filled created datetime.
	UpdatedAt            string        // (Optional) The filed name of table for automatic-filled updated datetime.
	DeletedAt            string        // (Optional) The filed name of table for automatic-filled updated datetime.
	TimeMaintainDisabled bool          // (Optional) Disable the automatic time maintaining feature.
}

ConfigNode is configuration for one node.

func (*ConfigNode) String

func (node *ConfigNode) String() string

String returns the node as string.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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