db

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package db provide useful functions to create mysql instance.

Index

Constants

This section is empty.

Variables

ProviderSet is db providers.

Functions

func NewMySQL

func NewMySQL(opts *MySQLOptions) (*gorm.DB, error)

NewMySQL create a new gorm db instance with the given options.

func NewRedis

func NewRedis(opts *RedisOptions) (*redis.Client, error)

NewRedis create a new gorm db instance with the given options.

Types

type MySQLOptions

type MySQLOptions struct {
	Host                  string
	Username              string
	Password              string
	Database              string
	MaxIdleConnections    int
	MaxOpenConnections    int
	MaxConnectionLifeTime time.Duration
	// +optional
	Logger logger.Interface
}

MySQLOptions defines optsions for mysql database.

func (*MySQLOptions) DSN

func (o *MySQLOptions) DSN() string

DSN return DSN from MySQLOptions.

type RedisOptions

type RedisOptions struct {
	Addr         string
	Username     string
	Password     string
	Database     int
	MaxRetries   int
	MinIdleConns int
	DialTimeout  time.Duration
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
	PoolTimeout  time.Duration
	PoolSize     int
}

RedisOptions defines optsions for mysql database.

type TracePlugin

type TracePlugin struct{}

TracePlugin defines gorm plugin used to trace sql.

func (*TracePlugin) Initialize

func (op *TracePlugin) Initialize(db *gorm.DB) (err error)

Initialize initialize the trace plugin.

func (*TracePlugin) Name

func (op *TracePlugin) Name() string

Name returns the name of trace plugin.

Jump to

Keyboard shortcuts

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