pgconn

package
v0.0.0-...-904665a Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NetworkAddress

func NetworkAddress(host string, port uint16) (network, address string)

func SafeToRetry

func SafeToRetry(err error) bool

func Timeout

func Timeout(err error) bool

Types

type AfterConnectFunc

type AfterConnectFunc func(ctx context.Context, pgconn PgConn) error

type Batch

type Batch interface {
	ExecParams(sql string, paramValues [][]byte, paramOIDs []uint32, paramFormats []int16, resultFormats []int16)
	ExecPrepared(stmtName string, paramValues [][]byte, paramFormats []int16, resultFormats []int16)
}

type BuildFrontendFunc

type BuildFrontendFunc func(r io.Reader, w io.Writer) Frontend

type CommandTag

type CommandTag interface {
	Delete() bool
	Insert() bool
	RowsAffected() int64
	Select() bool
	String() string
	Update() bool
}

type ConcreteConfig

type ConcreteConfig Config

type ConcreteNotification

type ConcreteNotification struct {
	*pgconn.Notification
}

func (*ConcreteNotification) Channel

func (c *ConcreteNotification) Channel() string

func (*ConcreteNotification) PID

func (c *ConcreteNotification) PID() uint32

func (*ConcreteNotification) Payload

func (c *ConcreteNotification) Payload() string

func (*ConcreteNotification) SetChannel

func (c *ConcreteNotification) SetChannel(s string) Notification

func (*ConcreteNotification) SetPID

func (*ConcreteNotification) SetPayload

func (c *ConcreteNotification) SetPayload(s string) Notification

type Config

type Config interface {
	Host() string
	Port() uint16
	Database() string
	User() string
	Password() string
	TLSConfig() *tls.Config // nil disables TLS
	ConnectTimeout() time.Duration
	DialFunc() DialFunc     // e.g. net.Dialer.DialContext
	LookupFunc() LookupFunc // e.g. net.Resolver.LookupHost
	BuildFrontend() BuildFrontendFunc
	RuntimeParams() map[string]string // Run-time parameters to set on connection as session default values (e.g. search_path or application_name)

	Fallbacks() []FallbackConfig

	// ValidateConnect is called during a connection attempt after a successful authentication with the PostgreSQL server.
	// It can be used to validate that the server is acceptable. If this returns an error the connection is closed and the next
	// fallback config is tried. This allows implementing high availability behavior such as libpq does with target_session_attrs.
	ValidateConnect() ValidateConnectFunc

	// AfterConnect is called after ValidateConnect. It can be used to set up the connection (e.g. Set session variables
	// or prepare statements). If this returns an error the connection attempt fails.
	AfterConnect() AfterConnectFunc

	// OnNotice is a callback function called when a notice response is received.
	OnNotice() NoticeHandler

	// OnNotification is a callback function called when a notification from the LISTEN/NOTIFY system is received.
	OnNotification() NotificationHandler

	Copy() Config
}

func ParseConfig

func ParseConfig(connString string) (Config, error)

func PgconnConfigFromBasePgconnConfig

func PgconnConfigFromBasePgconnConfig(basePgconn.Config) Config

type DialFunc

type DialFunc = pgconn.DialFunc

type FallbackConfig

type FallbackConfig interface {
	Host() string
	Port() uint16
	TLSConfig() *tls.Config

	SetHost(string) FallbackConfig
	SetPort(uint16) FallbackConfig
	SetTLSConfig(config *tls.Config) FallbackConfig
}

type Frontend

type Frontend = pgconn.Frontend

type HijackedConn

type HijackedConn interface {
	Config() Config
	Conn() net.Conn
	Frontend() Frontend
	ParameterStatuses() map[string]string
	PID() uint32
	SecretKey() uint32
	TxStatus() byte

	SetConfig(Config) HijackedConn
	SetConn(net.Conn) HijackedConn
	SetFrontend(Frontend) HijackedConn
	SetParameterStatuses(map[string]string) HijackedConn
	SetPID(uint32) HijackedConn
	SetSecretKey(uint32) HijackedConn
	SetTxStatus(byte) HijackedConn
}

type LookupFunc

type LookupFunc = pgconn.LookupFunc

type MultiResultReader

type MultiResultReader interface {
	Close() error
	NextResult() bool
	ReadAll() ([]*Result, error)
	ResultReader() *ResultReader
}

type Notice

type Notice = pgconn.Notice

type NoticeHandler

type NoticeHandler func(PgConn, Notice)

type Notification

type Notification interface {
	Channel() string
	Payload() string
	PID() uint32

	SetChannel(string) Notification
	SetPayload(string) Notification
	SetPID(uint32) Notification
}

type NotificationHandler

type NotificationHandler func(PgConn, Notification)

type PgConn

type PgConn interface {
	CancelRequest(ctx context.Context) error
	CleanupDone() chan (struct{})
	Close(ctx context.Context) error
	Conn() net.Conn
	CopyFrom(ctx context.Context, r io.Reader, sql string) (CommandTag, error)
	CopyTo(ctx context.Context, w io.Writer, sql string) (CommandTag, error)
	EscapeString(s string) (string, error)
	Exec(ctx context.Context, sql string) *MultiResultReader
	ExecBatch(ctx context.Context, batch *Batch) *MultiResultReader
	ExecParams(ctx context.Context, sql string, paramValues [][]byte, paramOIDs []uint32, paramFormats []int16, resultFormats []int16) *ResultReader
	ExecPrepared(ctx context.Context, stmtName string, paramValues [][]byte, paramFormats []int16, resultFormats []int16) *ResultReader
	Hijack() (*HijackedConn, error)
	IsBusy() bool
	IsClosed() bool
	ParameterStatus(key string) string
	PID() uint32
	Prepare(ctx context.Context, name, sql string, paramOIDs []uint32) (*StatementDescription, error)
	ReceiveMessage(ctx context.Context) (pgproto3.BackendMessage, error)
	ReceiveResults(ctx context.Context) *MultiResultReader
	SecretKey() uint32
	SendBytes(ctx context.Context, buf []byte) error
	TxStatus() byte
	WaitForNotification(ctx context.Context) error
}

func Connect

func Connect(ctx context.Context, connString string) (PgConn, error)

func ConnectConfig

func ConnectConfig(ctx context.Context, config Config) (pgConn PgConn, err error)

func Construct

func Construct(hc HijackedConn) (PgConn, error)

type PgError

type PgError = pgconn.PgError

func ErrorResponseToPgError

func ErrorResponseToPgError(msg *pgproto3.ErrorResponse) *PgError

type Result

type Result interface {
	CommandTag() CommandTag
	Err() error
	FieldDescriptions() []pgproto3.FieldDescription
	Rows() [][][]byte

	SetCommandTag(CommandTag) Result
	SetErr(error) Result
	SetFieldDescriptions([]pgproto3.FieldDescription) Result
	SetRows([][][]byte) Result
}

type ResultReader

type ResultReader interface {
	Close() (CommandTag, error)
	FieldDescriptions() []pgproto3.FieldDescription
	NextRow() bool
	Read() Result
	Values() [][]byte
}

type StatementDescription

type StatementDescription interface {
	Fields() []pgproto3.FieldDescription
	Name() string
	ParamOIDs() []uint32
	SQL() string

	SetFields([]pgproto3.FieldDescription) StatementDescription
	SetName(string) StatementDescription
	SetParamOIDs([]uint32) StatementDescription
	SetSQL(string) StatementDescription
}

type ValidateConnectFunc

type ValidateConnectFunc func(ctx context.Context, pgconn PgConn) error

Jump to

Keyboard shortcuts

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