pgx is a pure Go driver and toolkit for PostgreSQL providing a native high-performance interface with PostgreSQL-specific features plus a database/sql compatibility adapter.
—
pgproto3 implements the PostgreSQL frontend/backend wire protocol. It provides message types and read/write implementations for building PostgreSQL clients, servers, and proxies.
import "github.com/jackc/pgx/v5/pgproto3"const ProtocolVersionNumber = 196608 // PostgreSQL protocol version 3.0
const (
TextFormat = 0
BinaryFormat = 1
)
// Authentication types
const (
AuthTypeOk = 0
AuthTypeCleartextPassword = 3
AuthTypeMD5Password = 5
AuthTypeSCMCreds = 6
AuthTypeGSS = 7
AuthTypeGSSCont = 8
AuthTypeSASL = 10
AuthTypeSASLContinue = 11
AuthTypeSASLFinal = 12
)type Frontend struct{ /* unexported */ }
func NewFrontend(r io.Reader, w io.Writer) *Frontendfunc (f *Frontend) Send(msg FrontendMessage) error
func (f *Frontend) SendUnbufferedEncodedCopyData(data []byte) errorfunc (f *Frontend) Receive() (BackendMessage, error)func (f *Frontend) Trace(w io.Writer, options TracerOptions)
func (f *Frontend) Untrace()type Backend struct{ /* unexported */ }
func NewBackend(r io.Reader, w io.Writer) *Backendfunc (b *Backend) Receive() (FrontendMessage, error)
func (b *Backend) SetAuthType(authType uint32) errorfunc (b *Backend) Send(msg BackendMessage) errorfunc (b *Backend) Trace(w io.Writer, options TracerOptions)
func (b *Backend) Untrace()type TracerOptions struct {
SuppressTimestamps bool
}type Message interface {
// common interface for all messages
}
type FrontendMessage interface {
// messages sent by client to server
}
type BackendMessage interface {
// messages sent by server to client
}type StartupMessage struct {
ProtocolVersion uint32
Parameters map[string]string
}
type CancelRequest struct {
ProcessID uint32
SecretKey uint32
}
type SSLRequest struct{}
type GSSEncRequest struct{}
type Query struct {
String string
}
type Parse struct {
Name string
Query string
ParameterOIDs []uint32
}
type Bind struct {
DestinationPortal string
PreparedStatement string
ParameterFormatCodes []int16
Parameters [][]byte
ResultFormatCodes []int16
}
type Describe struct {
ObjectType byte // 'S' for prepared statement, 'P' for portal
Name string
}
type Execute struct {
Portal string
MaxRows uint32
}
type Close struct {
ObjectType byte // 'S' for prepared statement, 'P' for portal
Name string
}
type Sync struct{}
type Flush struct{}
type Terminate struct{}
type CopyData struct {
Data []byte
}
type CopyDone struct{}
type CopyFail struct {
Message string
}
type PasswordMessage struct {
Password string
}
type SASLInitialResponse struct {
AuthMechanism string
Data []byte
}
type SASLResponse struct {
Data []byte
}
type GSSResponse struct {
Data []byte
}
type FunctionCall struct {
ObjectID uint32
ArgumentFormats []int16
Arguments [][]byte
ResultFormat int16
}type AuthenticationOk struct{}
type AuthenticationCleartextPassword struct{}
type AuthenticationMD5Password struct {
Salt [4]byte
}
type AuthenticationGSS struct{}
type AuthenticationGSSContinue struct {
Data []byte
}
type AuthenticationSASL struct {
AuthMechanisms []string
}
type AuthenticationSASLContinue struct {
Data []byte
}
type AuthenticationSASLFinal struct {
Data []byte
}
type AuthenticationResponseMessage interface {
// marker interface for auth response messages
}
type BackendKeyData struct {
ProcessID uint32
SecretKey uint32
}
type BindComplete struct{}
type CloseComplete struct{}
type EmptyQueryResponse struct{}
type NoData struct{}
type ParseComplete struct{}
type PortalSuspended struct{}
type CommandComplete struct {
CommandTag []byte
}
type DataRow struct {
Values [][]byte
}
type ErrorResponse struct {
Severity string
SeverityUnlocalized string
Code string
Message string
Detail string
Hint string
Position int32
InternalPosition int32
InternalQuery string
Where string
SchemaName string
TableName string
ColumnName string
DataTypeName string
ConstraintName string
File string
Line int32
Routine string
// ... and UnknownFields map[byte]string
}
type NoticeResponse ErrorResponse // same structure as ErrorResponse
type FieldDescription struct {
Name string
TableOID uint32
TableAttributeNumber uint16
DataTypeOID uint32
DataTypeSize int16
TypeModifier int32
Format int16
}
type RowDescription struct {
Fields []FieldDescription
}
type ParameterDescription struct {
ParameterOIDs []uint32
}
type ParameterStatus struct {
Name string
Value string
}
type ReadyForQuery struct {
TxStatus byte // 'I'=idle, 'T'=in transaction, 'E'=failed transaction
}
type NotificationResponse struct {
PID uint32
Channel string
Payload string
}
type CopyInResponse struct {
OverallFormat byte
ColumnFormatCodes []uint16
}
type CopyOutResponse struct {
OverallFormat byte
ColumnFormatCodes []uint16
}
type CopyBothResponse struct {
OverallFormat byte
ColumnFormatCodes []uint16
}
type CopyData struct {
Data []byte
}
type CopyDone struct{}
type FunctionCallResponse struct {
Result []byte
}type ExceededMaxBodyLenErr struct {
MaxBodyLen int
ActualBodyLen int
}type BigEndianBuf [8]byteMethods on BigEndianBuf for encoding integers in big-endian format:
(b *BigEndianBuf) Int16(n int16) []byte(b *BigEndianBuf) Int32(n int32) []byte(b *BigEndianBuf) Int64(n int64) []byte(b *BigEndianBuf) Uint16(n uint16) []byte(b *BigEndianBuf) Uint32(n uint32) []byte(b *BigEndianBuf) Uint64(n uint64) []bytepgproto3 is primarily used internally by pgx and pgconn.Frontend or Backend.Install with Tessl CLI
npx tessl i tessl/golang-github-com-jackc-pgx-v5