Documentation ¶
Index ¶
- Constants
- Variables
- type Message
- func BackendKeyData(pid int32, secret int32) Message
- func CommandComplete(tag string) Message
- func DataRow(vals []string) Message
- func ErrorResponse(err error) Message
- func ParameterStatus(name, value string) Message
- func RowDescription(cols, types []string) Message
- func TLSResponse(supported bool) Message
- func (m Message) CancelKeyData() (int32, int32, error)
- func (m *Message) CreatesTransaction() bool
- func (m *Message) EndsTransaction() bool
- func (m Message) IsCancel() bool
- func (m Message) IsTLSRequest() bool
- func (m Message) IsTerminate() bool
- func (m Message) QueryText() (string, error)
- func (m Message) StartupArgs() (map[string]interface{}, error)
- func (m Message) StartupVersion() (string, error)
- func (m Message) Type() byte
- type MessageReadWriter
- type Transport
Constants ¶
const ( Query = 'Q' Terminate = 'X' Parse = 'P' Bind = 'B' Describe = 'D' Execute = 'E' Sync = 'S' )
frontend message types
Variables ¶
var BindComplete = []byte{'2', 0, 0, 0, 4}
BindComplete is sent when backend prepared a portal and finished planning the query
var ParseComplete = []byte{'1', 0, 0, 0, 4}
ParseComplete is sent when backend parsed a prepared statement successfully
var ReadyForQuery = []byte{'Z', 0, 0, 0, 5, 'I'}
ReadyForQuery is sent whenever the backend is ready for a new query cycle.
var TypesOid = map[string]int{
"BOOL": 16,
"BYTEA": 17,
"CHAR": 18,
"INT8": 20,
"INT2": 21,
"INT4": 23,
"TEXT": 25,
"JSON": 114,
"XML": 142,
"FLOAT4": 700,
"FLOAT8": 701,
"VARCHAR": 1043,
"DATE": 1082,
"TIME": 1083,
"TIMESTAMP": 1114,
"TIMESTAMPZ": 1184,
"INTERVAL": 1186,
"NUMERIC": 1700,
"JSONB": 3802,
"ANY": 2276,
}
TypesOid maps between a type name to its corresponding OID
Functions ¶
This section is empty.
Types ¶
type Message ¶
type Message []byte
Message is just an alias for a slice of bytes that exposes common operations on Postgres' client-server protocol messages. see: https://www.postgresql.org/docs/current/protocol-message-formats.html for postgres specific list of message formats
func BackendKeyData ¶
BackendKeyData creates a new message providing the client with a process ID and secret key that it can later use to cancel running queries
func CommandComplete ¶
CommandComplete is sent when query was fully executed and cursor reached the end of the row set
func ErrorResponse ¶
ErrorResponse is sent whenever error has occurred
func ParameterStatus ¶
ParameterStatus creates a new message providing parameter name and value
func RowDescription ¶
RowDescription is a message indicating that DataRow messages are about to be transmitted and delivers their schema (column names/types)
func TLSResponse ¶
TLSResponse creates a new single byte message indicating if the server supports TLS or not. If it does, the client must immediately proceed to initiate the TLS handshake
func (Message) CancelKeyData ¶
CancelKeyData returns the key data of a cancel message
func (*Message) CreatesTransaction ¶
CreatesTransaction tells weather this is a frontend message that should start/continue a transaction
func (*Message) EndsTransaction ¶
EndsTransaction tells weather this is a frontend message that should end the current transaction
func (Message) IsTLSRequest ¶
IsTLSRequest determines if this startup message is actually a request to open a TLS connection, in which case the version number is a special, predefined value of "1234.5679"
func (Message) IsTerminate ¶
IsTerminate determines if the current message is a notification that the client has terminated the connection upon user-request.
func (Message) StartupArgs ¶
StartupArgs parses the arguments delivered in the Startup and returns them as a key-value map. Startup messages contains a map of arguments, like the requested database name, user name, charset and additional connection defaults that may be used by the server. These arguments are encoded as pairs of key-values, terminated by a NULL character.
func (Message) StartupVersion ¶
StartupVersion returns the protocol version supported by the client. The version is encoded by two consecutive 2-byte integers, one for the major version, and the other for the minor version. Currently version 3.0 is the only valid version.
type MessageReadWriter ¶
MessageReadWriter describes objects that handle client-server communication. Objects implementing this interface are used by logic operations to send Message objects to frontend and receive Message back from it
type Transport ¶
Transport manages the underlying wire protocol between backend and frontend.
func NewTransport ¶
NewTransport creates a protocol
func (*Transport) NextMessage ¶
NextMessage reads and returns a single message from the connection when available. if within a transaction, the transaction will read from the connection, otherwise a ReadyForQuery message will first be sent to the frontend and then reading a single message from the connection will happen
NextMessage expects to be called only after a call to StartUp without an error response otherwise, an error is returned