db

package
v0.1.140 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(config map[string]interface{}) (interface{}, error)

DB client component, wrapper for database/sql, support read-write splitting, configuration: components:

db:
    driver: "mysql"
    dsn:    "user:pass@tcp(127.0.0.1:3306)/db?charset=utf8&timeout=0.5s"
    slaves: ["slave1 dsn", "slave2 dsn"]
    maxIdleConn: 5
    maxOpenConn: 10
    sqlLog:false
    maxConnTime: "1h"
    slowLogTime: "100ms"

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func (*Client) GetDb

func (c *Client) GetDb(master bool) *sql.DB

GetDb get a master or slave db instance

func (*Client) Init

func (c *Client) Init() error

func (*Client) SetDriver

func (c *Client) SetDriver(driver string)

SetDriver set driver db use, eg. "mysql"

func (*Client) SetDsn

func (c *Client) SetDsn(dsn string)

SetDsn set master dsn, the dsn is driver specified, eg. dsn format for github.com/go-sql-driver/mysql is [username[:password]@][protocol[(address)]]/dbname[?param=value]

func (*Client) SetMaxConnTime

func (c *Client) SetMaxConnTime(v string) error

SetMaxConnTime set conn life time, default is 1h

func (*Client) SetMaxIdleConn

func (c *Client) SetMaxIdleConn(maxIdleConn int)

SetMaxIdleConn set max idle conn, default is 5

func (*Client) SetMaxOpenConn

func (c *Client) SetMaxOpenConn(maxOpenConn int)

SetMaxOpenConn set max open conn, default is 0

func (*Client) SetSlaves

func (c *Client) SetSlaves(v []interface{})

SetSlaves set dsn for slaves

func (*Client) SetSlowLogTime

func (c *Client) SetSlowLogTime(v string) error

SetSlowTime set slow log time, default is 100ms

func (*Client) SetSqlLog

func (c *Client) SetSqlLog(sqlLog bool)

func (*Client) SlowLogTime

func (c *Client) SlowLogTime() time.Duration

func (*Client) SqlLog

func (c *Client) SqlLog() bool

Jump to

Keyboard shortcuts

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