Documentation
¶
Index ¶
- Constants
- Variables
- func CreateCommandComplete(tag string) []byte
- func CreateMessage(msgType byte, payload []byte) []byte
- func CreateReadyForQuery(status byte) []byte
- type ColumnInfo
- type ConnectionState
- type Message
- type MockedPortal
- type Proxy
- type ResultHandler
- func (r *ResultHandler) SendCommandComplete(conn net.Conn, tag string) error
- func (r *ResultHandler) SendDataRow(conn net.Conn, columns []string, values map[string]interface{}) error
- func (r *ResultHandler) SendDataRowWithFormats(conn net.Conn, columns []string, values map[string]interface{}, ...) error
- func (r *ResultHandler) SendEmptyResultSet(conn net.Conn, columns []string) error
- func (r *ResultHandler) SendRowDescription(conn net.Conn, columns []string) error
- func (r *ResultHandler) SendRowDescriptionWithHints(conn net.Conn, columns []string, sampleRow map[string]interface{}) error
- type StartupHandler
Constants ¶
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
const ( AuthOK = 0 AuthKerberosV5 = 2 AuthCleartextPassword = 3 AuthMD5Password = 5 AuthSCMCredential = 6 AuthGSS = 7 AuthGSSContinue = 8 AuthSSPI = 9 AuthSASL = 10 )
Authentication types
Variables ¶
var SSLRequest = []byte{0x00, 0x00, 0x00, 0x08, 0x04, 0xD2, 0x16, 0x2F}
SSLRequest magic number
Functions ¶
func CreateCommandComplete ¶
CreateCommandComplete creates CommandComplete message
func CreateMessage ¶
CreateMessage creates a message with given type and payload
func CreateReadyForQuery ¶
CreateReadyForQuery creates ReadyForQuery message status: 'I' = Idle, 'T' = In transaction, 'E' = Failed transaction
Types ¶
type ColumnInfo ¶
type ConnectionState ¶
type ConnectionState struct {
// contains filtered or unexported fields
}
ConnectionState tracks prepared statements and mocked portals per connection This is needed for the extended query protocol where we eavesdrop on Parse but only intercept at Bind/Execute
func NewConnectionState ¶
func NewConnectionState() *ConnectionState
NewConnectionState creates a new connection state
type MockedPortal ¶
type MockedPortal struct {
Mock *types.ExpectStatement
Query string // actual SQL captured at Parse/Bind time
DescribeForwarded bool // true if Describe was forwarded to upstream for this stmt
ResultFormatCodes []int16 // per-column result format codes from Bind (0=text, 1=binary)
}
MockedPortal pairs a matched mock with the actual SQL query from Parse, so sendMockExecuteResponse can use the real SELECT/INSERT/UPDATE text rather than falling back to a synthetic "INSERT INTO <table>" string. DescribeForwarded records whether a Describe was forwarded for this statement before Bind, meaning the upstream already sent RowDescription to the client — the Execute response must therefore omit RowDescription to avoid a duplicate.
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) ResetConnections ¶
func (p *Proxy) ResetConnections()
ResetConnections closes all active client and upstream connections. Called on registry reload so that the service's connection pool reconnects with fresh state, eliminating stale mock-only prepared statement mappings that would otherwise persist across test boundaries.
func (*Proxy) SetResolver ¶
func (p *Proxy) SetResolver(resolver *interpolate.Resolver)
SetResolver wires an interpolate.Resolver into the payload loader so that ${VAR} tokens in RETURNS payload files are resolved at runtime.
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 using name-based heuristics to choose binary vs text format per column (legacy behaviour).
func (*ResultHandler) SendDataRowWithFormats ¶
func (r *ResultHandler) SendDataRowWithFormats(conn net.Conn, columns []string, values map[string]interface{}, resultFormatCodes []int16) error
SendDataRowWithFormats sends a DataRow honouring the per-column result format codes that the client supplied in its Bind message (0=text, 1=binary). A slice with a single entry applies that code to every column; an empty/nil slice falls back to name-based heuristics.
func (*ResultHandler) SendEmptyResultSet ¶
func (r *ResultHandler) SendEmptyResultSet(conn net.Conn, columns []string) error
SendEmptyResultSet sends an empty result set
func (*ResultHandler) SendRowDescription ¶
func (r *ResultHandler) SendRowDescription(conn net.Conn, columns []string) error
SendRowDescription sends RowDescription message
func (*ResultHandler) SendRowDescriptionWithHints ¶
func (r *ResultHandler) SendRowDescriptionWithHints(conn net.Conn, columns []string, sampleRow map[string]interface{}) error
SendRowDescriptionWithHints sends a RowDescription, using the provided sample row to refine per-column OID inference. Falls back to SendRowDescription when sampleRow is nil.
type StartupHandler ¶
type StartupHandler struct{}
StartupHandler manages the connection startup phase
func NewStartupHandler ¶
func NewStartupHandler() *StartupHandler