orm

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DriverMySQL mysql driver
	DriverMySQL = "mysql"
	// DriverPostgres postgresSQL driver
	DriverPostgres = "postgres"

	// DefaultDatabase default db name
	DefaultDatabase = "default"
)

Variables

View Source
var (
	// DBMap store database instance
	DBMap = make(map[string]*gorm.DB)
	// DBLock database locker
	DBLock sync.Mutex
)

Functions

func GetDB added in v1.8.2

func GetDB(name string) (*gorm.DB, error)

GetDB get a database

func New added in v1.8.2

func New(names ...string) error

New create a or multi database client

func NewInstance added in v1.8.2

func NewInstance(c *Config) (db *gorm.DB)

NewInstance connect to database and create a db instance

Types

type Config

type Config struct {
	Driver          string
	Name            string
	Addr            string
	UserName        string
	Password        string
	ShowLog         bool
	MaxIdleConn     int
	MaxOpenConn     int
	Timeout         string // connect timeout
	ReadTimeout     string
	WriteTimeout    string
	ConnMaxLifeTime time.Duration
	SlowThreshold   time.Duration // 慢查询时长,默认500ms
}

Config database config

func LoadConf added in v1.8.2

func LoadConf(name string) (ret *Config, err error)

LoadConf load database config

type Manager added in v1.8.2

type Manager struct {
	*sync.RWMutex
	// contains filtered or unexported fields
}

Manager define a manager

func NewManager added in v1.8.2

func NewManager() *Manager

NewManager create a database manager

func (*Manager) GetInstance added in v1.8.2

func (m *Manager) GetInstance(name string) (*gorm.DB, error)

GetInstance return a database client

Jump to

Keyboard shortcuts

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