db

package
v0.2.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 12 Imported by: 1

Documentation

Overview

Package db provide useful functions to create mysql instance.

Index

Constants

This section is empty.

Variables

ProviderSet is db providers.

Functions

func MustRawDB

func MustRawDB(db *gorm.DB) *sql.DB

func NewMySQL

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

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

func NewPostgreSQL

func NewPostgreSQL(opts *PostgreSQLOptions) (*gorm.DB, error)

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

func NewRedis

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

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

Types

type MySQLOptions

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

MySQLOptions defines options for mysql database.

func (*MySQLOptions) DSN

func (o *MySQLOptions) DSN() string

DSN return DSN from MySQLOptions.

type PostgreSQLOptions

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

PostgreSQLOptions defines options for PostgreSQL database.

func (*PostgreSQLOptions) DSN

func (o *PostgreSQLOptions) DSN() string

DSN return DSN from PostgreSQLOptions.

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 options for redis 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