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 pool_sticky.go reader.go reader_buf.go reader_bytes.go write_buffer.go

Variables

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

func PutReaderContext Uses

func PutReaderContext(rd *ReaderContext)

func PutWriteBuffer Uses

func PutWriteBuffer(wb *WriteBuffer)

type BadConnError Uses

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

func (BadConnError) Error Uses

func (e BadConnError) Error() string

func (BadConnError) Unwrap Uses

func (e BadConnError) Unwrap() error

type BufReader Uses

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

func NewBufReader Uses

func NewBufReader(bufSize int) *BufReader

func (*BufReader) Available Uses

func (b *BufReader) Available() int

func (*BufReader) Buffered Uses

func (b *BufReader) Buffered() int

Buffered returns the number of bytes that can be read from the current buffer.

func (*BufReader) Bytes Uses

func (b *BufReader) Bytes() []byte

func (*BufReader) BytesReader Uses

func (b *BufReader) BytesReader(n int) *BytesReader

func (*BufReader) Discard Uses

func (b *BufReader) Discard(n int) (discarded int, err error)

Discard skips the next n bytes, returning the number of bytes discarded.

If Discard skips fewer than n bytes, it also returns an error. If 0 <= n <= b.Buffered(), Discard is guaranteed to succeed without reading from the underlying io.BufReader.

func (*BufReader) Read Uses

func (b *BufReader) Read(p []byte) (n int, err error)

func (*BufReader) ReadByte Uses

func (b *BufReader) ReadByte() (byte, error)

func (*BufReader) ReadBytes Uses

func (b *BufReader) ReadBytes(fn func(byte) bool) (line []byte, err error)

func (*BufReader) ReadFull Uses

func (b *BufReader) ReadFull() ([]byte, error)

func (*BufReader) ReadFullTemp Uses

func (b *BufReader) ReadFullTemp() ([]byte, error)

func (*BufReader) ReadN Uses

func (b *BufReader) ReadN(n int) (line []byte, err error)

func (*BufReader) ReadSlice Uses

func (b *BufReader) ReadSlice(delim byte) (line []byte, err error)

ReadSlice reads until the first occurrence of delim in the input, returning a slice pointing at the bytes in the buffer. The bytes stop being valid at the next read. If ReadSlice encounters an error before finding a delimiter, it returns all the data in the buffer and the error itself (often io.EOF). ReadSlice fails with error ErrBufferFull if the buffer fills without a delim. Because the data returned from ReadSlice will be overwritten by the next I/O operation, most clients should use ReadBytes or ReadString instead. ReadSlice returns err != nil if and only if line does not end in delim.

func (*BufReader) Reset Uses

func (b *BufReader) Reset(rd io.Reader)

func (*BufReader) SetAvailable Uses

func (b *BufReader) SetAvailable(n int)

func (*BufReader) UnreadByte Uses

func (b *BufReader) UnreadByte() error

type BytesReader Uses

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

func NewBytesReader Uses

func NewBytesReader(b []byte) *BytesReader

func (*BytesReader) Buffered Uses

func (r *BytesReader) Buffered() int

func (*BytesReader) Bytes Uses

func (r *BytesReader) Bytes() []byte

func (*BytesReader) Discard Uses

func (r *BytesReader) Discard(n int) (int, error)

func (*BytesReader) Read Uses

func (r *BytesReader) Read(b []byte) (n int, err error)

func (*BytesReader) ReadByte Uses

func (r *BytesReader) ReadByte() (byte, error)

func (*BytesReader) ReadBytes Uses

func (r *BytesReader) ReadBytes(fn func(byte) bool) ([]byte, error)

func (*BytesReader) ReadFull Uses

func (r *BytesReader) ReadFull() ([]byte, error)

func (*BytesReader) ReadFullTemp Uses

func (r *BytesReader) ReadFullTemp() ([]byte, error)

func (*BytesReader) ReadN Uses

func (r *BytesReader) ReadN(n int) ([]byte, error)

func (*BytesReader) ReadSlice Uses

func (r *BytesReader) ReadSlice(delim byte) ([]byte, error)

func (*BytesReader) Reset Uses

func (r *BytesReader) Reset(b []byte)

func (*BytesReader) UnreadByte Uses

func (r *BytesReader) UnreadByte() error

type ColumnAlloc Uses

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

func NewColumnAlloc Uses

func NewColumnAlloc() *ColumnAlloc

func (*ColumnAlloc) Columns Uses

func (c *ColumnAlloc) Columns() []ColumnInfo

func (*ColumnAlloc) New Uses

func (c *ColumnAlloc) New(index int16, name []byte) *ColumnInfo

func (*ColumnAlloc) Reset Uses

func (c *ColumnAlloc) Reset()

type ColumnInfo Uses

type ColumnInfo struct {
    Index    int16
    DataType int32
    Name     string
}

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) LockReader Uses

func (cn *Conn) LockReader()

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(
    ctx context.Context, timeout time.Duration, fn func(rd *ReaderContext) error,
) error

func (*Conn) WithWriter Uses

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

func (*Conn) WriteBuffer Uses

func (cn *Conn) WriteBuffer(ctx context.Context, timeout time.Duration, wb *WriteBuffer) 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(ctx 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(ctx context.Context, cn *Conn)

func (*ConnPool) ReapStaleConns Uses

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

func (*ConnPool) Remove Uses

func (p *ConnPool) Remove(ctx context.Context, cn *Conn, reason error)

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(context.Context, *Conn)
    Remove(context.Context, *Conn, error)

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

    Close() error
}

type Reader Uses

type Reader interface {
    Buffered() int

    Bytes() []byte
    Read([]byte) (int, error)
    ReadByte() (byte, error)
    UnreadByte() error
    ReadSlice(byte) ([]byte, error)
    Discard(int) (int, error)

    // ReadBytes(fn func(byte) bool) ([]byte, error)
    // ReadN(int) ([]byte, error)
    ReadFull() ([]byte, error)
    ReadFullTemp() ([]byte, error)
}

type ReaderContext Uses

type ReaderContext struct {
    *BufReader
    ColumnAlloc *ColumnAlloc
}

func GetReaderContext Uses

func GetReaderContext() *ReaderContext

func NewReaderContext Uses

func NewReaderContext() *ReaderContext

type SingleConnPool Uses

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

func NewSingleConnPool Uses

func NewSingleConnPool(pool Pooler, cn *Conn) *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(ctx 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(ctx context.Context) (*Conn, error)

func (*SingleConnPool) Put Uses

func (p *SingleConnPool) Put(ctx context.Context, cn *Conn)

func (*SingleConnPool) Remove Uses

func (p *SingleConnPool) Remove(ctx context.Context, cn *Conn, reason error)

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 StickyConnPool Uses

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

func NewStickyConnPool Uses

func NewStickyConnPool(pool Pooler) *StickyConnPool

func (*StickyConnPool) Close Uses

func (p *StickyConnPool) Close() error

func (*StickyConnPool) CloseConn Uses

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

func (*StickyConnPool) Get Uses

func (p *StickyConnPool) Get(ctx context.Context) (*Conn, error)

func (*StickyConnPool) IdleLen Uses

func (p *StickyConnPool) IdleLen() int

func (*StickyConnPool) Len Uses

func (p *StickyConnPool) Len() int

func (*StickyConnPool) NewConn Uses

func (p *StickyConnPool) NewConn(ctx context.Context) (*Conn, error)

func (*StickyConnPool) Put Uses

func (p *StickyConnPool) Put(ctx context.Context, cn *Conn)

func (*StickyConnPool) Remove Uses

func (p *StickyConnPool) Remove(ctx context.Context, cn *Conn, reason error)

func (*StickyConnPool) Reset Uses

func (p *StickyConnPool) Reset(ctx context.Context) error

func (*StickyConnPool) Stats Uses

func (p *StickyConnPool) Stats() *Stats

type WriteBuffer Uses

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

func GetWriteBuffer Uses

func GetWriteBuffer() *WriteBuffer

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) Query Uses

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

func (*WriteBuffer) ReadFrom Uses

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

func (*WriteBuffer) Reset Uses

func (buf *WriteBuffer) Reset()

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 15 packages (graph) and is imported by 14 packages. Updated 2020-12-05. Refresh now. Tools for package owners.