adb

package
v1.7.8 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Master map[string]*gorm.DB
)

Functions

func Close

func Close()

Close 关闭数据库

func CreateConnection added in v1.7.3

func CreateConnection(config DatabaseConfig) (db *gorm.DB, err error)

CreateConnection creates a single database connection based on the configuration 创建基于配置的单个数据库连接

func GetDatabase added in v1.7.3

func GetDatabase(name string) *gorm.DB

GetDatabase retrieves a database connection by name 通过名称检索数据库连接

func InitDb

func InitDb(connections []map[string]any)

InitDb initializes the database connections based on the configuration 初始化基于配置的数据库连接

func Mysql

func Mysql(dsn string) gorm.Dialector

Mysql connection Mysql连接

func Postgres

func Postgres(dsn string) gorm.Dialector

Postgres connection Postgres连接

func Sqlserver

func Sqlserver(dsn string) gorm.Dialector

Sqlserver connection Sqlserver连接

Types

type DatabaseConfig added in v1.7.3

type DatabaseConfig struct {
	Name            string              `json:"name"`
	Type            string              `json:"type"`
	Hostname        string              `json:"hostname"`
	Port            string              `json:"port"`
	Username        string              `json:"username"`
	Password        string              `json:"password"`
	DatabaseName    string              `json:"database"`
	Params          string              `json:"params"`
	LogEnabled      bool                `json:"log"`
	DSN             string              `json:"dsn"`
	MaxIdleConns    int                 `json:"max_idle_conns"`
	MaxOpenConns    int                 `json:"max_open_conns"`
	ConnMaxLifetime int                 `json:"conn_max_lifetime"`
	ConnMaxIdleTime int                 `json:"conn_max_idleTime"`
	LogLevel        gormlogger.LogLevel `json:"level"`
}

func (*DatabaseConfig) Distributed added in v1.7.3

func (d *DatabaseConfig) Distributed(config dbresolver.Config, datas ...interface{}) *dbresolver.DBResolver

Distributed 分布式

func (*DatabaseConfig) Open added in v1.7.3

func (d *DatabaseConfig) Open(Dialector gorm.Dialector, opts gorm.Option) (db *gorm.DB, err error)

Open connection

func (*DatabaseConfig) Use added in v1.7.3

func (d *DatabaseConfig) Use(name string, plugin gorm.Plugin)

Use

type Logger

type Logger struct {
	ZapLogger                 *zap.Logger
	LogLevel                  gormlogger.LogLevel
	SlowThreshold             time.Duration
	SkipCallerLookup          bool
	IgnoreRecordNotFoundError bool
}

func New

func New(zapLogger *zap.Logger) Logger

func (Logger) Error

func (l Logger) Error(ctx context.Context, str string, args ...interface{})

func (Logger) Info

func (l Logger) Info(ctx context.Context, str string, args ...interface{})

func (Logger) LogMode

func (l Logger) LogMode(level gormlogger.LogLevel) gormlogger.Interface

func (Logger) SetAsDefault

func (l Logger) SetAsDefault()

func (Logger) Trace

func (l Logger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

func (Logger) Warn

func (l Logger) Warn(ctx context.Context, str string, args ...interface{})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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