orm

package
v1.2.12 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DriverMySQL     = "mysql"
	DriverPostgres  = "postgres"
	DriverPostgres2 = "postgresql"

	DefaultMySQLConfig     = "charset=utf8mb4&parseTime=true&loc=Asia%2FShanghai"
	DefaultPostgresConfig  = "sslmode=disable&TimeZone=Asia/Shanghai"
	DefaultSlowThresholdMs = 1000
)

Variables

This section is empty.

Functions

func ConnectDatabase added in v1.2.12

func ConnectDatabase(m Mysql) (*gorm.DB, error)

func ConnectMysql

func ConnectMysql(m Mysql) (*gorm.DB, error)

func NormalizeDriver added in v1.2.12

func NormalizeDriver(driver string) string

func Ping

func Ping(dsn string) bool

func PingDatabase added in v1.2.12

func PingDatabase(driver, dsn string) bool

Types

type Config

type Config struct {
	Driver        string `yaml:"Driver" default:"mysql"`
	Addr          string `yaml:"Addr"`
	Username      string `yaml:"Username"`
	Password      string `yaml:"Password"`
	Dbname        string `yaml:"Dbname"`
	Config        string `yaml:"Config" default:"charset=utf8mb4&parseTime=true&loc=Asia%2FShanghai"`
	MaxIdleConns  int    `yaml:"MaxIdleConns" default:"10"`
	MaxOpenConns  int    `yaml:"MaxOpenConns" default:"10"`
	SlowThreshold int64  `yaml:"SlowThreshold" default:"1000"`
}

func ParseDSN

func ParseDSN(dsn string) *Config

type Mysql

type Mysql struct {
	Config Config
}

func (Mysql) Driver added in v1.2.12

func (m Mysql) Driver() string

func (Mysql) Dsn

func (m Mysql) Dsn() string

func (*Mysql) GetColorful

func (m *Mysql) GetColorful() bool

func (*Mysql) GetSlowThreshold

func (m *Mysql) GetSlowThreshold() time.Duration

func (Mysql) MigrationDsn added in v1.2.12

func (m Mysql) MigrationDsn() string

Jump to

Keyboard shortcuts

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