database

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DriverMysql    = "mysql"
	DriverPostgres = "postgres"
)

Variables

This section is empty.

Functions

func Get

func Get(ctx context.Context, name ...string) *gorm.DB

Get 获取数据库

func Register

func Register(dsn, driver string, opts ...Option) error

Register 注册默认数据库 当只有一个数据库的时候推荐使用

func RegisterByName

func RegisterByName(name, dsn, driver string, opts ...Option) error

RegisterByName 按名称注册数据库 适合同时需要操作多个数据库

func RegisterFromConfig

func RegisterFromConfig(cfgs map[string]Config) error

Types

type Config

type Config struct {
	Url             string
	Driver          string
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxIdleTime time.Duration
}

type Option

type Option func(*gorm.DB) error

Option 数据库的一些配置

func WithConnMaxIdleTime

func WithConnMaxIdleTime(n time.Duration) Option

func WithMaxIdleConns

func WithMaxIdleConns(n int) Option

func WithMaxOpenConns

func WithMaxOpenConns(n int) Option

Jump to

Keyboard shortcuts

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