connection

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2021 License: GPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

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

Driver list

Variables

This section is empty.

Functions

func GetMongoClient

func GetMongoClient(url string) *mongo.Client

Types

type Client

type Client struct {
	URI     string `json:"uri" mapstructure:"uri"`
	DB      string `json:"database" mapstructure:"database"`
	AppName string `json:"name" mapstructure:"name"`
	// on second
	ConnectTimeout time.Duration
	// on second
	PingTimeout time.Duration
}

func (*Client) MongoConnect

func (c *Client) MongoConnect() (mc *mongo.Client, err error)

type DB

type DB struct {
	DBConnection  *sqlx.DB
	DBString      string
	RetryInterval int
	MaxIdleConn   int
	MaxConn       int
	// contains filtered or unexported fields
}

DB configuration

var (
	Master *DB
	Slave  *DB
)

Db object

func (*DB) Connect

func (d *DB) Connect(driver string) error

Connect to database

func (*DB) ConnectAndMonitor

func (d *DB) ConnectAndMonitor(driver string) error

ConnectAndMonitor to database

type DBConfig

type DBConfig struct {
	SlaveDSN      string `json:"slave_dsn" mapstructure:"slave_dsn"`
	MasterDSN     string `json:"master_dsn" mapstructure:"master_dsn"`
	RetryInterval int    `json:"retry_interval" mapstructure:"retry_interval"`
	MaxIdleConn   int    `json:"max_idle" mapstructure:"max_idle"`
	MaxConn       int    `json:"max_con" mapstructure:"max_con"`
}

DBConfig for databases configuration

type DSNConfig

type DSNConfig struct {
	DSN string
}

DSNConfig for database source name

type Database

type Database struct {
	Database *mongo.Database
}

func MongoConnectClient

func MongoConnectClient(c *Client) *Database

type Store

type Store struct {
	Master *sqlx.DB
	Slave  *sqlx.DB
}

func New

func New(cfg DBConfig, dbDriver string) *Store

func (*Store) GetMaster

func (s *Store) GetMaster() *sqlx.DB

func (*Store) GetSlave

func (s *Store) GetSlave() *sqlx.DB

Jump to

Keyboard shortcuts

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