pg: github.com/go-pg/pg/internal/pool Index | Files

package pool

import "github.com/go-pg/pg/internal/pool"

Index

Package Files

conn.go pool.go pool_single.go write_buffer.go

Variables

var ErrClosed = errors.New("pg: database is closed")
var ErrPoolTimeout = errors.New("pg: connection pool timeout")

type Conn Uses

type Conn struct {
    ProcessID int32
    SecretKey int32

    Inited bool
    // contains filtered or unexported fields
}

func NewConn Uses

func NewConn(netConn net.Conn) *Conn

func (*Conn) Close Uses

func (cn *Conn) Close() error

func (*Conn) NetConn Uses

func (cn *Conn) NetConn() net.Conn

func (*Conn) NextID Uses

func (cn *Conn) NextID() string

func (*Conn) RemoteAddr Uses

func (cn *Conn) RemoteAddr() net.Addr

func (*Conn) SetNetConn Uses

func (cn *Conn) SetNetConn(netConn net.Conn)

func (*Conn) SetUsedAt Uses

func (cn *Conn) SetUsedAt(tm time.Time)

func (*Conn) UsedAt Uses

func (cn *Conn) UsedAt() time.Time

func (*Conn) WithReader Uses

func (cn *Conn) WithReader(
    c context.Context, timeout time.Duration, fn func(rd *internal.BufReader) error,
) error

func (*Conn) WithWriter Uses

func (cn *Conn) WithWriter(
    c context.Context, timeout time.Duration, fn func(wb *WriteBuffer) error,
) error

type ConnPool Uses

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

func NewConnPool Uses

func NewConnPool(opt *Options) *ConnPool

func (*ConnPool) Close Uses

func (p *ConnPool) Close() error

func (*ConnPool) CloseConn Uses

func (p *ConnPool) CloseConn(cn *Conn) error

func (*ConnPool) Filter Uses

func (p *ConnPool) Filter(fn func(*Conn) bool) error

func (*ConnPool) Get Uses

func (p *ConnPool) Get(c context.Context) (*Conn, error)

Get returns existed connection from the pool or creates a new one.

func (*ConnPool) IdleLen Uses

func (p *ConnPool) IdleLen() int

IdleLen returns number of idle connections.

func (*ConnPool) Len Uses

func (p *ConnPool) Len() int

Len returns total number of connections.

func (*ConnPool) NewConn Uses

func (p *ConnPool) NewConn(c context.Context) (*Conn, error)

func (*ConnPool) Put Uses

func (p *ConnPool) Put(cn *Conn)

func (*ConnPool) ReapStaleConns Uses

func (p *ConnPool) ReapStaleConns() (int, error)

func (*ConnPool) Remove Uses

func (p *ConnPool) Remove(cn *Conn)

func (*ConnPool) Stats Uses

func (p *ConnPool) Stats() *Stats

type Options Uses

type Options struct {
    Dialer  func(context.Context) (net.Conn, error)
    OnClose func(*Conn) error

    PoolSize           int
    MinIdleConns       int
    MaxConnAge         time.Duration
    PoolTimeout        time.Duration
    IdleTimeout        time.Duration
    IdleCheckFrequency time.Duration
}

type Pooler Uses

type Pooler interface {
    NewConn(context.Context) (*Conn, error)
    CloseConn(*Conn) error

    Get(context.Context) (*Conn, error)
    Put(*Conn)
    Remove(*Conn)

    Len() int
    IdleLen() int
    Stats() *Stats

    Close() error
}

type SingleConnPool Uses

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

func NewSingleConnPool Uses

func NewSingleConnPool(pool Pooler) *SingleConnPool

func (*SingleConnPool) Clone Uses

func (p *SingleConnPool) Clone() *SingleConnPool

func (*SingleConnPool) Close Uses

func (p *SingleConnPool) Close() error

func (*SingleConnPool) CloseConn Uses

func (p *SingleConnPool) CloseConn(cn *Conn) error

func (*SingleConnPool) Get Uses

func (p *SingleConnPool) Get(c context.Context) (*Conn, error)

func (*SingleConnPool) IdleLen Uses

func (p *SingleConnPool) IdleLen() int

func (*SingleConnPool) Len Uses

func (p *SingleConnPool) Len() int

func (*SingleConnPool) NewConn Uses

func (p *SingleConnPool) NewConn(c context.Context) (*Conn, error)

func (*SingleConnPool) Put Uses

func (p *SingleConnPool) Put(cn *Conn)

func (*SingleConnPool) Remove Uses

func (p *SingleConnPool) Remove(cn *Conn)

func (*SingleConnPool) Reset Uses

func (p *SingleConnPool) Reset() error

func (*SingleConnPool) SetConn Uses

func (p *SingleConnPool) SetConn(cn *Conn)

func (*SingleConnPool) Stats Uses

func (p *SingleConnPool) Stats() *Stats

type Stats Uses

type Stats struct {
    Hits     uint32 // number of times free connection was found in the pool
    Misses   uint32 // number of times free connection was NOT found in the pool
    Timeouts uint32 // number of times a wait timeout occurred

    TotalConns uint32 // number of total connections in the pool
    IdleConns  uint32 // number of idle connections in the pool
    StaleConns uint32 // number of stale connections removed from the pool
}

Stats contains pool state information and accumulated stats.

type WriteBuffer Uses

type WriteBuffer struct {
    Bytes []byte
    // contains filtered or unexported fields
}

func NewWriteBuffer Uses

func NewWriteBuffer() *WriteBuffer

func (*WriteBuffer) FinishMessage Uses

func (buf *WriteBuffer) FinishMessage()

func (*WriteBuffer) FinishNullParam Uses

func (buf *WriteBuffer) FinishNullParam()

func (*WriteBuffer) FinishParam Uses

func (buf *WriteBuffer) FinishParam()

func (*WriteBuffer) Flush Uses

func (buf *WriteBuffer) Flush() []byte

func (*WriteBuffer) ReadFrom Uses

func (buf *WriteBuffer) ReadFrom(r io.Reader) (int64, error)

func (*WriteBuffer) Reset Uses

func (buf *WriteBuffer) Reset()

func (*WriteBuffer) ResetBuffer Uses

func (buf *WriteBuffer) ResetBuffer(b []byte)

func (*WriteBuffer) StartMessage Uses

func (buf *WriteBuffer) StartMessage(c byte)

func (*WriteBuffer) StartParam Uses

func (buf *WriteBuffer) StartParam()

func (*WriteBuffer) Write Uses

func (buf *WriteBuffer) Write(b []byte) (int, error)

func (*WriteBuffer) WriteByte Uses

func (buf *WriteBuffer) WriteByte(c byte) error

func (*WriteBuffer) WriteBytes Uses

func (buf *WriteBuffer) WriteBytes(b []byte)

func (*WriteBuffer) WriteInt16 Uses

func (buf *WriteBuffer) WriteInt16(num int16)

func (*WriteBuffer) WriteInt32 Uses

func (buf *WriteBuffer) WriteInt32(num int32)

func (*WriteBuffer) WriteString Uses

func (buf *WriteBuffer) WriteString(s string)

Package pool imports 11 packages (graph) and is imported by 10 packages. Updated 2019-07-13. Refresh now. Tools for package owners.