protocol

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: Apache-2.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

View Source
const (
	AuthenticationKerberosV5Required        = 2
	AuthenticationCleartextPasswordRequired = 3
	AuthenticationMD5PasswordRequired       = 5
	AuthenticationSCMCredentialRequired     = 6
	AuthenticationGSSRequired               = 7
	AuthenticationGSSContinueRequired       = 8
	AuthenticationSSPIRequired              = 9
	AuthenticationSASLRequired              = 10
	AuthenticationSASLContinueRequired      = 11
	AuthenticationSASLFinalRequired         = 12
	AuthenticationOk                        = 0
)
View Source
const (
	// TextCopy represents a textual copy format.
	TextCopy = CopyFormat(0)
	// BinaryCopy represents a binary copy format.
	BinaryCopy = CopyFormat(1)
)
View Source
const (
	// MessageTypeSize is the size of the message type.
	MessageTypeSize = 1
	// MessageLengthSize is the size of the message length.
	MessageLengthSize = 4
	// MessageHeaderSize is the size of the message header.
	MessageHeaderSize = MessageTypeSize + MessageLengthSize
)
View Source
const (
	ApplicationName = "application_name"
	ClientEncoding  = "client_encoding"
	ServerEncoding  = "server_ encoding"
	DateStyle       = "DateStyle"
	TimeZone        = "TimeZone"
	IntervalStyle   = "IntervalStyle"
)
View Source
const (
	DefaultTransactiOnReadOnly = "default_transaction_read_only"
	InHotStandby               = "in_hot_standby"
	IsSuperuser                = "is_superuser"
	OntegerDatetimes           = "integer_datetimes"
)

on/off parameters.

View Source
const (
	ServerVersion             = "#server_version"
	StandardConformingStrings = "#standard_conforming_strings"
)
View Source
const (
	// PreparedStatementByte represents a prepared statement.
	PreparedStatementByte = 'S'
	// PreparedPortalByte represents a prepared portal.
	PreparedPortalByte = 'P'
)
View Source
const (
	TransactionIdle   = 'I'
	TransactionBlock  = 'T'
	TransactionFailed = 'E'
)
View Source
const (
	SSLEnabled  = 'S'
	SSLDisabled = 'N'
)
View Source
const (
	StartUpUser            = "user"
	StartUpPassword        = "password"
	StartUpDatabase        = "database"
	StartUpApplicationName = "application_name"
	StartUpClientEncoding  = "client_encoding"
)
View Source
const (
	DateStyleISO = "ISO, MDY.S"
)
View Source
const (
	EncodingUTF8 = "UTF8"
)
View Source
const (
	NoneMessage = 0x00
)
View Source
const SSLRequestCode = 80877103

SSLRequestCode represents a SSLRequest message code.

Variables

View Source
var ErrExist = errors.New("exist")

ErrExist is returned when the specified object is exist.

View Source
var ErrInvalid = errors.New("invalid")

ErrInvalid is returned when the message is invalid.

View Source
var ErrNotExist = errors.New("not exist")

ErrNotExist is returned when the specified object is not exist.

View Source
var ErrNotSupported = errors.New("not supported")

ErrNotSupported is returned when the message is not supported.

Functions

func NewConnWith added in v1.5.9

func NewConnWith(netconn net.Conn, opts ...connOption) *conn

NewConnWith returns a connection with a raw connection.

func NewErrExist

func NewErrExist(v any) error

NewErrExist returns a new exist error.

func NewErrInvalidMessage

func NewErrInvalidMessage(t Type) error

NewErrInvalidMessage eturns a new message not supported error.

func NewErrMessageNotSuppoted

func NewErrMessageNotSuppoted(t Type) error

NewErrMessageNotSuppoted returns a new message not supported error.

func NewErrNotExist

func NewErrNotExist(v any) error

NewErrNotExist returns a new not exist error.

func WithConnDatabase added in v1.6.2

func WithConnDatabase(name string) func(*conn)

WithConnDatabase sets a database name.

func WithConnTLSConn added in v1.6.2

func WithConnTLSConn(s *tls.Conn) func(*conn)

WithConnTLSConn sets a TLS connection.

func WithConnTracer added in v1.6.2

func WithConnTracer(t tracer.Context) func(*conn)

WithConnTracer sets a tracer context.

func WithRowFieldDataType

func WithRowFieldDataType(dt *DataType) func(*RowField)

WithRowFieldDataType sets a data type.

func WithRowFieldFormatCode

func WithRowFieldFormatCode(formatCode int16) func(*RowField)

WithRowFieldFormatCode sets a format code.

func WithRowFieldModifier

func WithRowFieldModifier(typeModifier int32) func(*RowField)

WithRowFieldModifier sets a type modifier.

func WithRowFieldNumber

func WithRowFieldNumber(number int16) func(*RowField)

WithRowFieldNumber sets a number.

func WithRowFieldObjectID

func WithRowFieldObjectID(dataTypeID int32) func(*RowField)

WithRowFieldObjectID sets a data type ID.

func WithRowFieldSize

func WithRowFieldSize(dataTypeSize int16) func(*RowField)

WithRowFieldSize sets a data type size.

func WithRowFieldTableID

func WithRowFieldTableID(tableID int32) func(*RowField)

WithRowFieldTableID sets a table ID.

Types

type BackendKeyData

type BackendKeyData struct {
	*ResponseMessage
}

BackendKeyData represents a parameter status response protocol.

func NewBackendKeyData

func NewBackendKeyData() *BackendKeyData

NewBackendKeyData returns a parameter status response instance.

func NewBackendKeyDataWith

func NewBackendKeyDataWith(processID int32, secretKey int32) (*BackendKeyData, error)

NewBackendKeyDataWith returns a parameter status response instance with the specified parameters.

type Bind

type Bind struct {
	*RequestMessage
	PortalName    string
	StatementName string
	Params        BindParams
}

Bind represents a bind protocol.

func NewBindWithReader

func NewBindWithReader(reader *MessageReader) (*Bind, error)

NewBind returns a new bind protocol.

type BindComplete

type BindComplete struct {
	*ResponseMessage
}

BindComplete represents a bind complete protocol.

func NewBindComplete

func NewBindComplete() *BindComplete

NewBindComplete returns a new bind complete message instance.

type BindParam

type BindParam struct {
	FormatCode int16
	Value      any
}

BindParam represents a bind parameter.

type BindParams

type BindParams []*BindParam

BindParams represents bind parameters.

func (BindParams) FindBindParam

func (params BindParams) FindBindParam(id string) (*BindParam, error)

FindBindParam returns a bind parameter with specified id.

type Close

type Close struct {
	*RequestMessage
	Type PreparedType
	Name string
}

Close represents a close protocol.

func NewCloseWithReader

func NewCloseWithReader(reader *MessageReader) (*Close, error)

NewCloseWithReader returns a new close message with the specified reader.

type CloseComplete

type CloseComplete struct {
	*ResponseMessage
}

CloseComplete represents a close complete protocol.

func NewCloseComplete

func NewCloseComplete() *CloseComplete

NewCloseComplete returns a new close complete message instance.

type CommandComplete

type CommandComplete struct {
	*ResponseMessage
}

CommandComplete represents a command complete protocol.

func NewCommandComplete

func NewCommandComplete() *CommandComplete

NewCommandComplete returns a new command complete message instance.

func NewCommandCompleteWith

func NewCommandCompleteWith(tag string) (*CommandComplete, error)

NewInsertCompleteWith returns a new command complete message for insert query.

func NewCommitComplete

func NewCommitComplete() (*CommandComplete, error)

NewCommitComplete returns a new command complete message for commit query.

func NewCopyCompleteWith

func NewCopyCompleteWith(n int) (*CommandComplete, error)

NewCopyCompleteWith returns a new command complete message for copy query.

func NewDeleteCompleteWith

func NewDeleteCompleteWith(n int) (*CommandComplete, error)

NewDeleteCompleteWith returns a new command complete message for delete query.

func NewEmptyComplete

func NewEmptyComplete() (*CommandComplete, error)

NewEmptyComplete returns a new command complete message for empty ping query.

func NewInsertCompleteWith

func NewInsertCompleteWith(n int) (*CommandComplete, error)

NewInsertCompleteWith returns a new command complete message for insert query.

func NewSelectCompleteWith

func NewSelectCompleteWith(n int) (*CommandComplete, error)

NewSelectCompleteWith returns a new command complete message for select query.

func NewUpdateCompleteWith

func NewUpdateCompleteWith(n int) (*CommandComplete, error)

NewUpdateCompleteWith returns a new command complete message for update query.

type Config added in v1.5.9

type Config interface {
	tls.CertConfig

	// SetProuctName sets a product name to the configuration.
	SetProductName(v string)
	// SetProductVersion sets a product version to the configuration.
	SetProductVersion(v string)
	// ProductName returns the product name from the configuration.
	ProductName() string
	// ProductVersion returns the product version from the configuration.
	ProductVersion() string
	// SetAddress sets a listen address to the configuration.
	SetAddress(addr string)
	// SetPort sets a listen port to the configuration.
	SetPort(port int)
	// Address returns a listen address from the configuration.
	Address() string
	// Port returns a listen port from the configuration.
	Port() int
}

Config represents a server configuration.

func NewDefaultConfig added in v1.5.9

func NewDefaultConfig() Config

NewDefaultConfig returns a default configuration instance.

type Conn added in v1.5.9

type Conn interface {
	net.Conn
	MessageConn
	TLSConn
}

Conn represents a connection.

type ConnID added in v1.5.9

type ConnID = net.ConnID

ConnID represents a connection ID.

type CopyData

type CopyData struct {
	*RequestMessage
	Data []string
}

CopyData represents a copy data protocol.

func NewCopyDataWithReader

func NewCopyDataWithReader(reader *MessageReader) (*CopyData, error)

NewCopyDataWithReader returns a new copy data message with the specified reader.

type CopyDone

type CopyDone struct {
	*RequestMessage
}

CopyDone represents a copy done protocol.

func NewCopyDoneWithReader

func NewCopyDoneWithReader(reader *MessageReader) (*CopyDone, error)

NewCopyDataWithReader returns a new copy data message with the specified reader.

type CopyFail

type CopyFail struct {
	MessageLength int32
	Message       string
}

CopyFail represents a copy fail protocol.

func NewCopyFailWithReader

func NewCopyFailWithReader(reader *Reader) (*CopyFail, error)

NewCopyFailWithReader returns a new copy fail message with the specified reader.

type CopyFormat

type CopyFormat = int8

CopyFormat represents a copy format.

type CopyInResponse

type CopyInResponse struct {
	*ResponseMessage
	// contains filtered or unexported fields
}

CopyInResponse represents a command complete protocol.

func NewCopyInResponseWith

func NewCopyInResponseWith(fmt CopyFormat) *CopyInResponse

NewCopyInResponse returns a new command complete message instance.

func (*CopyInResponse) AppendFormatCode

func (msg *CopyInResponse) AppendFormatCode(formatCode int16)

AppendFormatCode appends a format code.

func (*CopyInResponse) Bytes

func (msg *CopyInResponse) Bytes() ([]byte, error)

Bytes appends a length of the message content bytes, and returns the message bytes.

type DataRow

type DataRow struct {
	*ResponseMessage
	Data []any
}

DataRow represents a data row protocol.

func NewDataRow

func NewDataRow() *DataRow

NewDataRow returns a new data row message instance.

func (*DataRow) AppendData

func (msg *DataRow) AppendData(rowField *RowField, v any) error

AppendData appends a column value to the data row protocol.

func (*DataRow) Bytes

func (msg *DataRow) Bytes() ([]byte, error)

Bytes appends a length of the message content bytes, and returns the message bytes.

type DataType

type DataType = system.DataType

DataType represents a data type.

type Describe

type Describe struct {
	*RequestMessage
	Type PreparedType
	Name string
}

Describe represents a describe protocol.

func NewDescribeWithReader

func NewDescribeWithReader(reader *MessageReader) (*Describe, error)

NewDescribeWithReader returns a new describe message with the specified reader.

type EmptyQueryResponse

type EmptyQueryResponse struct {
	*ResponseMessage
}

EmptyQueryResponse represents an empty query response protocol.

func NewEmptyQueryResponse

func NewEmptyQueryResponse() *EmptyQueryResponse

NewEmptyQueryResponse returns an empty query response message instance.

type ErrorResponse

type ErrorResponse struct {
	*ResponseMessage
}

ErrorResponse represents an error response protocol.

func NewErrorResponse

func NewErrorResponse() *ErrorResponse

NewErrorResponse returns a new error response instance.

func NewErrorResponseWith

func NewErrorResponseWith(err error) (*ErrorResponse, error)

NewErrorResponseWith returns a new error response instance with the specified error.

func (*ErrorResponse) AddCode

func (msg *ErrorResponse) AddCode(code int32) error

AddCode adds an error code to the error response.

func (*ErrorResponse) AddError

func (msg *ErrorResponse) AddError(err error) error

AddError adds an error message to the error response.

func (*ErrorResponse) AppendField

func (msg *ErrorResponse) AppendField(t ErrorType, v string) error

AppendField appends an error field to the error response.

func (*ErrorResponse) Bytes

func (msg *ErrorResponse) Bytes() ([]byte, error)

Bytes returns the message bytes after adding a null terminator.

type ErrorType

type ErrorType byte

ErrorType represents a error response type.

const (
	SeverityError         ErrorType = 'S'
	CodeError             ErrorType = 'C'
	MessageError          ErrorType = 'M'
	DetailError           ErrorType = 'D'
	HintError             ErrorType = 'H'
	PositionError         ErrorType = 'P'
	InternalPositionError ErrorType = 'p'
	InternalQueryError    ErrorType = 'q'
	WhereError            ErrorType = 'W'
	SchemaError           ErrorType = 's'
	TableError            ErrorType = 't'
	ColumnError           ErrorType = 'c'
	DataTypeNameError     ErrorType = 'd'
	ConstraintError       ErrorType = 'n'
	FileError             ErrorType = 'F'
	LineError             ErrorType = 'L'
	RoutineError          ErrorType = 'R'
)

type Execute

type Execute struct {
	*RequestMessage
	PortalName string
	MaxRows    int32
}

Execute represents an execute protocol.

func NewExecuteWithReader

func NewExecuteWithReader(reader *MessageReader) (*Execute, error)

NewExecute returns a new execute protocol.

type ExtendedQueryHandler added in v1.5.9

type ExtendedQueryHandler interface {
	// Prepare handles a parse
	Parse(Conn, *Parse) (Responses, error)
	// Bind handles a bind
	Bind(Conn, *Bind) (Responses, error)
	// Describe handles a describe
	Describe(Conn, *Describe) (Responses, error)
	// Execute handles a execute
	Execute(Conn, *Execute) (Responses, error)
	// Close handles a close
	Close(Conn, *Close) (Responses, error)
	// Sync handles a sync
	Sync(Conn, *Sync) (Responses, error)
	// Flush handles a flush
	Flush(Conn, *Flush) (Responses, error)
}

ExtendedQueryHandler defines a executor interface for extended query operations.

type Flush

type Flush struct {
	*RequestMessage
}

Flush represents a flush protocol.

func NewFlushWithReader

func NewFlushWithReader(reader *MessageReader) (*Flush, error)

NewFlush returns a new flush protocol.

type FormatCode

type FormatCode = system.FormatCode

FormatCode represents a format code.

const (
	// TextFormat represents a text format code.
	TextFormat FormatCode = system.TextFormat
	// BinaryFormat represents a binary format code.
	BinaryFormat FormatCode = system.BinaryFormat
)

type Message

type Message struct {
	*MessageReader
	Type   Type
	Length int32
}

Message represents a message of PostgreSQL packet.

func NewMessageWithReader

func NewMessageWithReader(reader *MessageReader) (*Message, error)

NewMessageWithReader returns a new message with the specified reader.

func (*Message) MessageDataLength

func (msg *Message) MessageDataLength() int32

MessageLength returns a message data length without the message header.

func (*Message) MessageLength

func (msg *Message) MessageLength() int32

MessageLength returns a message length.

func (*Message) MessageType

func (msg *Message) MessageType() Type

MessageType returns a message type.

func (*Message) ReadMessageData

func (msg *Message) ReadMessageData() ([]byte, error)

ReadMessageData reads all message data.

type MessageConn added in v1.5.9

type MessageConn interface {
	// MessageReader returns a message reader.
	MessageReader() *MessageReader
	// ResponseMessage sends a response
	ResponseMessage(resMsg Response) error
	// ResponseMessages sends response messages.
	ResponseMessages(resMsgs Responses) error
	// ResponseError sends an error response.
	ResponseError(err error) error
	// SkipMessage skips a
	SkipMessage() error
	// ReadyForMessage sends a ready for
	ReadyForMessage(status TransactionStatus) error
}

MessageConn represents a message connection.

type MessageHandler added in v1.5.9

type MessageHandler interface {
	StartupHandler
	QueryHandler
}

MessageHandler represents a message handler.

type MessageReader

type MessageReader struct {
	*Reader
	Type   Type
	Length int32
}

func NewMessageReaderWith

func NewMessageReaderWith(reader io.Reader) *MessageReader

NewMessageReader returns a new message reader.

func (*MessageReader) IsPeekType

func (reader *MessageReader) IsPeekType(t Type) (bool, error)

IsPeekType returns true whether the peeked message type is the specified type.

func (*MessageReader) PeekType

func (reader *MessageReader) PeekType() (Type, error)

PeekType peeks a message type.

func (*MessageReader) ReadLength

func (reader *MessageReader) ReadLength() (int32, error)

ReadLength reads a message length.

func (*MessageReader) ReadType

func (reader *MessageReader) ReadType() (Type, error)

ReadType reads a message type.

type NoData

type NoData struct {
	*ResponseMessage
}

NoData represents a no data protocol.

func NewNoData

func NewNoData() *NoData

NewNoData returns a new no data message instance.

type ObjectID

type ObjectID = system.ObjectID

ObjectID represents a object identifier.

type ParameterDescription

type ParameterDescription struct {
	*ResponseMessage
}

ParameterDescription represents a parameter description response protocol.

func NewParameterDescription

func NewParameterDescription() *ParameterDescription

NewParameterDescription returns a parameter description response instance.

func NewParameterDescriptionWith

func NewParameterDescriptionWith(objectIDs ...ObjectID) (*ParameterDescription, error)

NewParameterDescriptionWith returns a parameter description response instance with the specified parameters.

type ParameterStatus

type ParameterStatus struct {
	*ResponseMessage
}

ParameterStatus represents a parameter status response protocol.

func NewParameterStatus

func NewParameterStatus() *ParameterStatus

NewParameterStatus returns a parameter status response instance.

func NewParameterStatusWith

func NewParameterStatusWith(name string, value string) (*ParameterStatus, error)

NewParameterStatusWith returns a parameter status response instance with the specified parameter status.

func (*ParameterStatus) AppendParameters

func (msg *ParameterStatus) AppendParameters(s ...string) error

AppendParameters appends the specified parameters.

type Parse

type Parse struct {
	*RequestMessage
	Name         string
	Query        string
	NumDataTypes int16
	DataTypes    []int32
}

Parse represents a parse protocol.

func NewParseWithReader

func NewParseWithReader(reader *MessageReader) (*Parse, error)

NewParseWithReader returns a new parse message with the specified reader.

type ParseComplete

type ParseComplete struct {
	*ResponseMessage
}

ParseComplete represents a parser complete protocol.

func NewParseComplete

func NewParseComplete() *ParseComplete

NewParseComplete returns a parser complete instance.

type Password

type Password struct {
	*RequestMessage
	Password string
}

Password represents a password protocol.

func NewPasswordWithReader

func NewPasswordWithReader(reader *MessageReader) (*Password, error)

NewPasswordWithReader returns a new password protocol.

type PreparedType

type PreparedType int

PreparedType represents a prepared type.

const (
	// PreparedStatement represents a prepared statement.
	PreparedStatement PreparedType = iota
	// PreparedPortal represents a prepared portal.
	PreparedPortal
)

func NewPreparedTypeWithByte

func NewPreparedTypeWithByte(bt byte) (PreparedType, error)

NewPreparedTypeWithByte returns a new prepared type with the specified byte.

type Query

type Query struct {
	*RequestMessage
	Query string
	BindParams
}

Query represents a parse protocol.

func NewQueryWith

func NewQueryWith(parseMsg *Parse, bindMsg *Bind) (*Query, error)

NewQueryWith returns a new query message with specified parameters.

func NewQueryWithReader

func NewQueryWithReader(reader *MessageReader) (*Query, error)

NewQueryWithReader returns a new query message with specified reader.

type QueryHandler added in v1.5.9

type QueryHandler interface {
	SimpleQueryHandler
	ExtendedQueryHandler
}

QueryHandler represents a query handler.

type Reader

type Reader struct {
	io.Reader
	// contains filtered or unexported fields
}

Reader represents a message reader.

func NewReaderWith

func NewReaderWith(reader io.Reader) *Reader

NewReader returns a new message reader.

func (*Reader) PeekBytes

func (reader *Reader) PeekBytes(n int) ([]byte, error)

func (*Reader) PeekInt32

func (reader *Reader) PeekInt32() (int32, error)

PeekInt32 reads a 32-bit integer.

func (*Reader) ReadByte

func (reader *Reader) ReadByte() (byte, error)

func (*Reader) ReadBytes

func (reader *Reader) ReadBytes(buf []byte) (int, error)

func (*Reader) ReadBytesUntil

func (reader *Reader) ReadBytesUntil(delim byte) ([]byte, error)

func (*Reader) ReadInt16

func (reader *Reader) ReadInt16() (int16, error)

ReadInt16 reads a 16-bit integer.

func (*Reader) ReadInt32

func (reader *Reader) ReadInt32() (int32, error)

ReadInt32 reads a 32-bit integer.

func (*Reader) ReadString

func (reader *Reader) ReadString() (string, error)

ReadString reads a string.

type ReadyForQuery

type ReadyForQuery struct {
	*ResponseMessage
}

ReadyForQuery represents a ready for query protocol.

func NewReadyForQuery

func NewReadyForQuery() *ReadyForQuery

NewReadyForQuery returns a new ready for query message instance.

func NewReadyForQueryWith

func NewReadyForQueryWith(s TransactionStatus) (*ReadyForQuery, error)

NewReadyForQueryWith returns a new error response instance with the specified error.

type RequestMessage

type RequestMessage struct {
	*Message
}

RequestMessage represents a frontend request.

func NewRequestMessageWithReader

func NewRequestMessageWithReader(reader *MessageReader) (*RequestMessage, error)

NewRequestMessageWithReader returns a new request message with the specified reader.

type Response

type Response interface {
	// Type returns the message type.
	Type() Type
	// Bytes returns the message bytes.
	Bytes() ([]byte, error)
}

Response represents a backend response message interface.

type ResponseMessage

type ResponseMessage struct {
	*Writer
	// contains filtered or unexported fields
}

ResponseMessage represents a backend response instance.

func NewAuthenticationCleartextPassword

func NewAuthenticationCleartextPassword() (*ResponseMessage, error)

NewAuthenticationCleartextPassword returns a new AuthenticationCleartextPassword protocol.

func NewAuthenticationMD5Password

func NewAuthenticationMD5Password(salt []byte) (*ResponseMessage, error)

NewAuthenticationMD5Password returns a new AuthenticationMD5Password protocol.

func NewAuthenticationOk

func NewAuthenticationOk() (*ResponseMessage, error)

NewAuthenticationOk returns a new AuthenticationOk protocol.

func NewResponseMessage

func NewResponseMessage() *ResponseMessage

NewResponseMessage returns a new request message instance.

func NewResponseMessageWith

func NewResponseMessageWith(t Type) *ResponseMessage

NewResponseMessageWith returns a new response message with the specified message type.

func (*ResponseMessage) Bytes

func (msg *ResponseMessage) Bytes() ([]byte, error)

Bytes appends a length of the message content bytes, and returns the message bytes.

func (*ResponseMessage) SetType

func (msg *ResponseMessage) SetType(t Type)

SetType sets a message type.

func (*ResponseMessage) Type

func (msg *ResponseMessage) Type() Type

Type returns the message type.

type Responses

type Responses []Response

Responses represents a list of response.

func NewCommandCompleteResponsesWith

func NewCommandCompleteResponsesWith(msg string) (Responses, error)

NewCommandCompleteResponsesWith returns a new responses with the specified protocol.

func NewCopyCompleteResponsesWith

func NewCopyCompleteResponsesWith(n int) (Responses, error)

NewCopyCompleteResponsesWith returns a new responses with the specified protocol.

func NewDeleteCompleteResponsesWith

func NewDeleteCompleteResponsesWith(n int) (Responses, error)

NewDeleteCompleteResponsesWith returns a new responses with the specified protocol.

func NewEmptyCompleteResponses

func NewEmptyCompleteResponses() (Responses, error)

NewEmptyCompleteResponses returns a new responses with the specified protocol.

func NewInsertCompleteResponsesWith

func NewInsertCompleteResponsesWith(n int) (Responses, error)

NewInsertCompleteResponsesWith returns a new responses with the specified protocol.

func NewParameterStatusesWith

func NewParameterStatusesWith(m map[string]string) (Responses, error)

NewParameterStatusesWith returns parameter status response instances with the specified parameter statuses.

func NewResponses

func NewResponses() Responses

NewResponses returns a new empty responses.

func NewResponsesWith

func NewResponsesWith(responses ...Response) Responses

NewResponsesWith returns a new responses with the specified responses.

func NewSelectCompleteResponsesWith

func NewSelectCompleteResponsesWith(n int) (Responses, error)

NewSelectCompleteResponsesWith returns a new responses with the specified protocol.

func NewUpdateCompleteResponsesWith

func NewUpdateCompleteResponsesWith(n int) (Responses, error)

NewUpdateCompleteResponsesWith returns a new responses with the specified protocol.

func (Responses) Append

func (responses Responses) Append(res Response) Responses

Append appends the specified response to this responses.

func (Responses) HasErrorResponse

func (responses Responses) HasErrorResponse() bool

HasErrorResponse returns true whether this responses has an error response.

type RowDescription

type RowDescription struct {
	*ResponseMessage
	// contains filtered or unexported fields
}

RowDescription represents a row description protocol.

func NewRowDescription

func NewRowDescription() *RowDescription

NewRowDescription returns a new row description message instance.

func (*RowDescription) AppendField

func (msg *RowDescription) AppendField(field *RowField)

AppendField appends a field to the protocol.

func (*RowDescription) Bytes

func (msg *RowDescription) Bytes() ([]byte, error)

Bytes appends a length of the message content bytes, and returns the message bytes.

func (*RowDescription) Field

func (msg *RowDescription) Field(n int) *RowField

Field returns a field at the specified index.

type RowField

type RowField struct {
	Name         string
	TableID      int32
	Number       int16
	ObjectID     int32
	DataTypeSize int16
	TypeModifier int32
	FormatCode   int16
}

RowField represents a row description field.

func NewRowFieldWith

func NewRowFieldWith(name string, opts ...RowFieldOption) *RowField

NewRowField returns a new row description field.

func (*RowField) WirteBytes

func (field *RowField) WirteBytes(w *Writer) error

WirteBytes appends a row field elements.

type RowFieldOption

type RowFieldOption = func(*RowField)

RowFieldOption represents a row description field option.

type SSLRequest

type SSLRequest struct {
	RequestCode int32
}

SSLRequest represents a SSLRequest protocol.

func NewSSLRequestWithReader

func NewSSLRequestWithReader(reader *MessageReader) (*SSLRequest, error)

NewSSLRequestWithReader returns a new SSLRequest message with the specified reader.

type SSLResponse

type SSLResponse struct {
	Enabled byte
}

SSLResponse represents a SSLResponse protocol.

func NewSSLResponseWith

func NewSSLResponseWith(enabled rune) *SSLResponse

NewSSLResponse returns a new SSLResponse protocol.

func (*SSLResponse) Bytes

func (msg *SSLResponse) Bytes() ([]byte, error)

Bytes returns a byte array of the protocol.

func (*SSLResponse) Type

func (msg *SSLResponse) Type() Type

Type returns the message type.

type Server added in v1.5.9

type Server interface {
	tracer.Tracer
	Config
	auth.Manager
	SetMessageHandler(MessageHandler)
	// SetTracer sets a tracing tracer.
	SetTracer(tracer.Tracer)
	// Start starts the server.
	Start() error
	// Stop stops the server.
	Stop() error
}

Server represents a PostgreSQL protocol server.

func NewServer added in v1.5.9

func NewServer() Server

NewServer returns a new server instance.

type SimpleQueryHandler added in v1.5.9

type SimpleQueryHandler interface {
	// Query handles a query
	Query(Conn, *Query) (Responses, error)
}

SimpleQueryHandler defines a executor interface for simple query operations.

type Startup

type Startup struct {
	MajorVersion  int
	MinorVersion  int
	MessageLength int32
	Parameters    map[string]string
}

Startup represents a startup protocol.

func NewStartupWithReader

func NewStartupWithReader(reader *MessageReader) (*Startup, error)

NewStartupWithReader returns a new startup message with the specified reader.

func (*Startup) ApplicationName

func (msg *Startup) ApplicationName() (string, bool)

ApplicationName returns the application name.

func (*Startup) ClientEncoding

func (msg *Startup) ClientEncoding() (string, bool)

ClientEncoding returns the client encoding.

func (*Startup) Database

func (msg *Startup) Database() (string, bool)

Database returns the database name.

func (*Startup) Password

func (msg *Startup) Password() (string, bool)

Password returns the password.

func (*Startup) User

func (msg *Startup) User() (string, bool)

User returns the user name.

type StartupHandler added in v1.5.9

type StartupHandler interface {
	// ParameterStatuses returns the parameter statuses.
	ParameterStatuses(Conn) (Responses, error)
	// BackendKeyData returns the backend key data.
	BackendKeyData(Conn) (Response, error)
}

StartupHandler represents a start-up message handler.

type Sync

type Sync struct {
	*RequestMessage
}

Sync represents a sync protocol.

func NewSyncWithReader

func NewSyncWithReader(reader *MessageReader) (*Sync, error)

NewSync returns a new sync protocol.

type TLSConn added in v1.5.9

type TLSConn interface {
	// IsTLSConnection return true if the connection is enabled TLS.
	IsTLSConnection() bool
	// TLSConn returns a TLS connection.
	TLSConn() *tls.Conn
}

TLSConn represents a TLS connection.

type Terminate

type Terminate struct {
	*RequestMessage
}

Terminate represents a terminate protocol.

func NewTerminateWithReader

func NewTerminateWithReader(reader *MessageReader) (*Terminate, error)

NewTerminate returns a new terminate protocol.

type TransactionStatus

type TransactionStatus = byte

TransactionStatus represents a transaction status.

type Type

type Type byte

Type represents a message type.

const (
	BindMessage                Type = 'B'
	CancelRequestMessage       Type = ' ' // Int32(16)
	CloseMessage               Type = 'C'
	CopyFailMessage            Type = 'f'
	DescribeMessage            Type = 'D'
	ExecuteMessage             Type = 'E'
	FlushMessage               Type = 'H'
	FunctionCallMessage        Type = 'F'
	GSSENCRequestMessage       Type = ' ' // Int32(8)
	GSSResponseMessage         Type = 'p'
	ParseMessage               Type = 'P'
	PasswordMessage            Type = 'p'
	QueryMessage               Type = 'Q'
	SASLInitialResponseMessage Type = 'p'
	SASLResponseMessage        Type = 'p'
	SSLRequestMessage          Type = ' ' // Int32(8)
	SSLResponseMessage         Type = ' '
	StartupMessage             Type = ' ' // Int32
	SyncMessage                Type = 'S'
	TerminateMessage           Type = 'X'
)

Frontend (F).

const (
	AuthenticationOkMessage                Type = 'R'
	AuthenticationKerberosV5Message        Type = 'R'
	AuthenticationCleartextPasswordMessage Type = 'R'
	AuthenticationMD5PasswordMessage       Type = 'R'
	AuthenticationGSSMessage               Type = 'R'
	AuthenticationSSPIMessage              Type = 'R'
	AuthenticationSASLMessage              Type = 'R'
	AuthenticationSASLContinueMessage      Type = 'R'
	AuthenticationSASLFinalMessage         Type = 'R'
	BackendKeyDataMessage                  Type = 'K'
	BindCompleteMessage                    Type = '2'
	CloseCompleteMessage                   Type = '3'
	CommandCompleteMessage                 Type = 'C'
	CopyInResponseMessage                  Type = 'G'
	CopyOutResponseMessage                 Type = 'H'
	CopyBothResponseMessage                Type = 'W'
	DataRowMessage                         Type = 'D'
	EmptyQueryResponseMessage              Type = 'I'
	ErrorResponseMessage                   Type = 'E'
	FunctionCallResponseMessage            Type = 'V'
	NegotiateProtocolVersionMessage        Type = 'v'
	NoDataMessage                          Type = 'n'
	NoticeResponseMessage                  Type = 'N'
	NotificationResponseMessage            Type = 'A'
	ParameterDescriptionMessage            Type = 't'
	ParameterStatusMessage                 Type = 'S'
	ParseCompleteMessage                   Type = '1'
	PortalSuspendedMessage                 Type = 's'
	ReadyForQueryMessage                   Type = 'Z'
	RowDescriptionMessage                  Type = 'T'
)

Backend (B).

const (
	CopyDataMessage Type = 'd'
	CopyDoneMessage Type = 'c'
)

Both (F & B).

func (Type) String

func (t Type) String() string

type Writer

type Writer struct {
	*bytes.Buffer
	*bufio.Writer
}

Writer represents a message writer.

func NewWriter

func NewWriter() *Writer

NewWriter returns a new message writer.

func (*Writer) AppendByte

func (writer *Writer) AppendByte(c byte) error

AppendByte appends the specified byte.

func (*Writer) AppendBytes

func (writer *Writer) AppendBytes(p []byte) error

AppendBytes appends the specified bytes.

func (*Writer) AppendFloat32

func (writer *Writer) AppendFloat32(v float32) error

AppendFloat32 appends the specified float32 value.

func (*Writer) AppendFloat64

func (writer *Writer) AppendFloat64(v float64) error

AppendFloat64 appends the specified float64 value.

func (*Writer) AppendInt16

func (writer *Writer) AppendInt16(v int16) error

AppendInt16 appends the specified int16 value.

func (*Writer) AppendInt32

func (writer *Writer) AppendInt32(v int32) error

AppendInt32 appends the specified int32 value.

func (*Writer) AppendInt64

func (writer *Writer) AppendInt64(v int64) error

AppendInt64 appends the specified int64 value.

func (*Writer) AppendInt8

func (writer *Writer) AppendInt8(v int8) error

AppendInt8 appends the specified int8 value.

func (*Writer) AppendString

func (writer *Writer) AppendString(s string) error

AppendString appends the specified string.

func (*Writer) AppendTerminator

func (writer *Writer) AppendTerminator() error

AppendTerminator appends a null terminator.

func (*Writer) Bytes

func (writer *Writer) Bytes() ([]byte, error)

Bytes returns the message bytes.

Jump to

Keyboard shortcuts

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