postgresql

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Frontend (client) messages
	MsgQuery      = 'Q'
	MsgParse      = 'P'
	MsgBind       = 'B'
	MsgExecute    = 'E'
	MsgSync       = 'S'
	MsgTerminate  = 'X'
	MsgDescribe   = 'D'
	MsgClose      = 'C'
	MsgFlush      = 'H'
	MsgSSLRequest = 0 // Special case
	MsgStartup    = 0 // Special case

	// Backend (server) messages
	MsgAuthentication       = 'R'
	MsgParameterStatus      = 'S'
	MsgBackendKeyData       = 'K'
	MsgReadyForQuery        = 'Z'
	MsgRowDescription       = 'T'
	MsgDataRow              = 'D'
	MsgCommandComplete      = 'C'
	MsgErrorResponse        = 'E'
	MsgNoticeResponse       = 'N'
	MsgParseComplete        = '1'
	MsgBindComplete         = '2'
	MsgCloseComplete        = '3'
	MsgNoData               = 'n'
	MsgPortalSuspended      = 's'
	MsgParameterDescription = 't'
)

Message types for Frontend/Backend protocol

View Source
const (
	AuthOK                = 0
	AuthKerberosV5        = 2
	AuthCleartextPassword = 3
	AuthMD5Password       = 5
	AuthSCMCredential     = 6
	AuthGSS               = 7
	AuthGSSContinue       = 8
	AuthSSPI              = 9
	AuthSASL              = 10
)

Authentication types

Variables

View Source
var SSLRequest = []byte{0x00, 0x00, 0x00, 0x08, 0x04, 0xD2, 0x16, 0x2F}

SSLRequest magic number

Functions

func CreateAuthenticationOk

func CreateAuthenticationOk() []byte

CreateAuthenticationOk creates AuthenticationOk message

func CreateBackendKeyData

func CreateBackendKeyData(processID, secretKey int32) []byte

CreateBackendKeyData creates BackendKeyData message

func CreateCommandComplete

func CreateCommandComplete(tag string) []byte

CreateCommandComplete creates CommandComplete message

func CreateMessage

func CreateMessage(msgType byte, payload []byte) []byte

CreateMessage creates a message with given type and payload

func CreateParameterDescription

func CreateParameterDescription(numParams uint16, paramTypes []uint32) []byte

CreateParameterDescription creates ParameterDescription message numParams is the number of parameters, paramTypes are the OIDs of the parameter types

func CreateParameterStatus

func CreateParameterStatus(name, value string) []byte

CreateParameterStatus creates ParameterStatus message

func CreateReadyForQuery

func CreateReadyForQuery(status byte) []byte

CreateReadyForQuery creates ReadyForQuery message status: 'I' = Idle, 'T' = In transaction, 'E' = Failed transaction

func ParseQuery

func ParseQuery(msg *Message) string

ParseQuery extracts SQL from Query message

func ParseStartupMessage

func ParseStartupMessage(msg *Message) map[string]string

ParseStartupMessage parses startup message parameters

func WriteMessage

func WriteMessage(conn net.Conn, msgType byte, payload []byte) error

WriteMessage writes a message to the connection

Types

type Message

type Message struct {
	Type    byte
	Length  int32
	Payload []byte
}

Message represents a PostgreSQL protocol message

func ReadMessage

func ReadMessage(conn net.Conn) (*Message, error)

ReadMessage reads a complete message from the connection Returns nil, nil if it's an SSL request

func ReadRegularMessage

func ReadRegularMessage(conn net.Conn) (*Message, error)

ReadRegularMessage reads a regular (non-startup) message

func ReadRegularMessageFromReader

func ReadRegularMessageFromReader(reader *bufio.Reader) (*Message, error)

ReadRegularMessageFromReader reads a regular message from a buffered reader

type Proxy

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

func NewProxy

func NewProxy(addr, upstreamAddr string, reg *registry.MockRegistry) *Proxy

NewProxy creates a new PostgreSQL proxy

func (*Proxy) Start

func (p *Proxy) Start(ctx context.Context) error

Start starts the proxy server

type ResultHandler

type ResultHandler struct{}

ResultHandler generates PostgreSQL result set messages

func NewResultHandler

func NewResultHandler() *ResultHandler

func (*ResultHandler) SendCommandComplete

func (r *ResultHandler) SendCommandComplete(conn net.Conn, tag string) error

SendCommandComplete sends just CommandComplete for non-SELECT operations

func (*ResultHandler) SendDataRow

func (r *ResultHandler) SendDataRow(conn net.Conn, columns []string, values map[string]interface{}) error

SendDataRow sends a single DataRow message

func (*ResultHandler) SendEmptyResultSet

func (r *ResultHandler) SendEmptyResultSet(conn net.Conn, columns []string) error

SendEmptyResultSet sends an empty result set

func (*ResultHandler) SendResultSet

func (r *ResultHandler) SendResultSet(conn net.Conn, columns []string, rows []map[string]interface{}) error

SendResultSet sends a complete result set to the client

func (*ResultHandler) SendRowDescription

func (r *ResultHandler) SendRowDescription(conn net.Conn, columns []string) error

SendRowDescription sends RowDescription message

type StartupHandler

type StartupHandler struct{}

StartupHandler manages the connection startup phase

func NewStartupHandler

func NewStartupHandler() *StartupHandler

func (*StartupHandler) HandleStartup

func (h *StartupHandler) HandleStartup(conn net.Conn) (map[string]string, error)

HandleStartup handles the initial connection phase Returns true if connection should proceed, false if it should be closed

func (*StartupHandler) HandleStartupWithReader

func (h *StartupHandler) HandleStartupWithReader(reader *bufio.Reader, conn net.Conn) (map[string]string, error)

HandleStartupWithReader handles startup using a provided buffered reader

Jump to

Keyboard shortcuts

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