gormpool

package module
v0.0.0-...-ec7c4c8 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrGetFromClosedPool           = errors.New("pool: get from closed pool")
	ErrExceedingMaxWaitingDuration = errors.New("pool: exceeding the maximum waiting duration")
)

Functions

This section is empty.

Types

type Conn

type Conn struct {
	DB  *gorm.DB
	Key string
	// contains filtered or unexported fields
}

type Options

type Options struct {
	DBType string

	DBArgs []interface{}

	// how many idle conn to keep when there are no work to do
	// this field should smaller than Capacity
	KeepConn uint64

	// Maximum number of connections allocated by the pool at a given time.
	// When zero, there is no limit on the number of connections in the pool.
	Capacity uint64

	MaxWaitDuration time.Duration
}

type Pool

type Pool struct {
	DBType string

	DBArgs []interface{}

	// how many idle conn to keep when there are no work to do
	// this field should smaller than Capacity
	KeepConn uint64

	// Maximum number of connections allocated by the pool at a given time.
	// When zero, there is no limit on the number of connections in the pool.
	Capacity uint64

	MaxWaitDuration time.Duration

	DBErrChan chan error // DB errors will be sent in this channel
	// contains filtered or unexported fields
}

func NewPool

func NewPool(ctx context.Context, opts Options) (p *Pool, err error)

func (*Pool) BusyConn

func (p *Pool) BusyConn() uint64

Get the number of current busy connections of the pool

func (*Pool) Close

func (p *Pool) Close()

func (*Pool) Get

func (p *Pool) Get() (conn *Conn, err error)

Get a SQL connection from the pool

func (*Pool) IdleConn

func (p *Pool) IdleConn() uint64

Get the number of current idle connections of the pool

func (*Pool) Put

func (p *Pool) Put(conn *Conn)

Put back a connection in the pool

func (*Pool) Size

func (p *Pool) Size() uint64

Get the number of current total connections of the pool

Jump to

Keyboard shortcuts

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