orm

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

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

	// 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
	// logWriter log writer
	LogWriter logger.Writer
)

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

func NewLogWriter added in v1.10.0

func NewLogWriter(log log.Logger) logger.Writer

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
	EnableTrace     bool
}

Config database config

func LoadConf added in v1.8.2

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

LoadConf load database config

type LoggerWriter added in v1.10.0

type LoggerWriter struct {
	// contains filtered or unexported fields
}

func (*LoggerWriter) Printf added in v1.10.0

func (l *LoggerWriter) Printf(s string, v ...interface{})

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