pg

package
v2.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCancelledMissingConnection = errors.New("cancelled connection does not exist")

ErrCancelledMissingConnection is an error triggered by cancelling a connection that does not exist.

View Source
var TypeCharoid = Type{/* contains filtered or unexported fields */}

TypeCharoid is a postgres type for text.

Functions

This section is empty.

Types

type CancellationManager

type CancellationManager interface {
	// Token acquires a new cancellation token.
	// The returned channel is sent to every time the connection is cancelled.
	// The connection may be cancelled an unlimited number of times.
	Token() (<-chan struct{}, context.CancelFunc, CancellationToken, error)

	// Cancel sends a cancellation notification to the connection with the associated token.
	// If the token is not associated with a connection, this returns ErrCancelledMissingConnection.
	Cancel(CancellationToken) error
}

CancellationManager manages postgres connection cancellation.

func NewLocalCancellationManager

func NewLocalCancellationManager(rand io.Reader) CancellationManager

NewLocalCancellationManager creates an in-memory CancellationManager using randomly generated tokens. The provided reader is expected to be secure (e.g. crypto/rand.Reader).

type CancellationToken

type CancellationToken struct {
	PID, Key int32
}

CancellationToken is a value used to identify a backend for cancellation.

type ColumnInfo

type ColumnInfo struct {
	Name    string
	Type    Type
	TableID int32
	FieldID int16
}

ColumnInfo contains metadata about a column.

type PrimitiveTypeEngine

type PrimitiveTypeEngine struct{}

PrimitiveTypeEngine is a simple type engine that only works on primitive types.

func (PrimitiveTypeEngine) TranslateType

func (pte PrimitiveTypeEngine) TranslateType(t Type) (message.ColumnDescription, error)

TranslateType translates a type to a column description.

type Protocol

type Protocol uint32

Protocol is a Postgres protocol version.

const (
	// ProtocolPostgres30 is version 3.0 of the Postgres wire protocol.
	ProtocolPostgres30 Protocol = (3 << 16)

	// ProtocolCancel is the protocol used for query cancellation.
	ProtocolCancel Protocol = (1234 << 16) | 5678

	// ProtocolSSL is the protocol used for SSL upgrades.
	ProtocolSSL Protocol = (1234 << 16) | 5679

	// ProtocolSupported is the main protocol version supported by this package.
	ProtocolSupported Protocol = ProtocolPostgres30
)

func (Protocol) Major

func (p Protocol) Major() uint16

Major returns the major revision of the protocol.

func (Protocol) Minor

func (p Protocol) Minor() uint16

Minor returns the minor revision of the protocol.

func (Protocol) String

func (p Protocol) String() string

type Query

type Query interface {
	fmt.Stringer
}

Query is an interface to be implemented by queries.

type QueryHandler

type QueryHandler interface {
	// HandleQuery executes a query and writes the results back.
	HandleQuery(context.Context, QueryResultWriter, Query) error
}

QueryHandler handles a query.

type QueryResultWriter

type QueryResultWriter interface {
	// WriteHeader sets the column header information.
	WriteHeader(...ColumnInfo) error

	// WriteRowText sends a row of data in textual format.
	WriteRowText(...string) error

	// Tag assigns a tag to the query.
	// This should be called before the query is completed.
	Tag(tag string)
}

QueryResultWriter is used to write the results of a query back over the connection.

type Server

type Server struct {
	// QueryHandler will be used to serve query requests.
	QueryHandler QueryHandler

	// TypeEngine is the type engine to use to result columns in query requests.
	TypeEngine TypeEngine

	// TLSConfig is the TLS configuration to use to serve postgres TLS connections.
	TLSConfig *tls.Config

	// StartupTimeout is the timeout to use for connection startup.
	// If a connection fails to set up a protocol before this completes, it will be terminated.
	StartupTimeout time.Duration

	// ReadTimeout is the timeout to apply for active reads (reads during the lifetime of a command).
	// This timeout does not apply to an idling connection.
	ReadTimeout time.Duration

	// WriteTimeout is the timeout to apply to network writes.
	WriteTimeout time.Duration

	// MaxStartupSize is the maximum size of the startup packet (in bytes).
	// This defaults to 2^31-1 bytes, which is the maximum size allowed by the protocol.
	MaxStartupSize uint32

	// ConnectionLimit is the maximum number of connections to allow at once.
	ConnectionLimit uint16

	// Logger is the logger to use for error conditions and state changes.
	Logger logger.Logger

	// CancellationManager is the cancellation manager to use.
	// If this is not set, no cancellations will be applied.
	CancellationManager CancellationManager
}

Server is a postgres wire protocol server.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, l net.Listener) (err error)

Serve accepts postgres connections from a listener and processes them. If the context is cancelled, this will stop accepting requests and wait until all connections have terminated. No error will be returned if terminated by context cancellation. This will close the connection for the caller.

func (*Server) ServeConn

func (s *Server) ServeConn(ctx context.Context, conn net.Conn) error

ServeConn serves a single connection.

type SimpleQuery

type SimpleQuery string

SimpleQuery is a query sent as only a string. It has no parameters.

func (SimpleQuery) String

func (q SimpleQuery) String() string

type Type

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

Type represents a postgres type.

type TypeData

type TypeData struct {
	TypeID       int32
	TypeLen      int16
	TypeModifier int32
}

TypeData is a type containing raw postgres wire type information.

type TypeEngine

type TypeEngine interface {
	// TranslateType populates a column description with type information.
	TranslateType(Type) (message.ColumnDescription, error)
}

TypeEngine is a system for managing types. This is necessary for compound types like arrays which need ID generation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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