database

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

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

Get 获取数据库

func Register

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

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

func RegisterByName

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

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

func RegisterFromConfig

func RegisterFromConfig(cfgs map[string]Config) error

Types

type Config

type Config struct {
	Url             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