postgresql

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: Apache-2.0 Imports: 13 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// PackageName is the package name.
	PackageName = "go-postgresql"
	// DefaultPort is the default port for PostgreSQL protocol server.
	DefaultPort = 5432
)
View Source
const (
	Version = "1.1.1"
)

Variables

This section is empty.

Functions

func WithConnDatabase

func WithConnDatabase(name string) func(*Conn)

WithConnDatabase sets the database name.

func WithConnTracer

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

WithConnDatabase sets the database name.

Types

type Authenticator

type Authenticator interface {
	// Authenticate handles the Start-up message and returns an Authentication or ErrorResponse message.
	Authenticate(*Conn, *message.Startup) (message.Response, error)
}

Authenticator represents a frontend message authenticator.

type BaseAuthenticator

type BaseAuthenticator struct {
}

BaseAuthenticator represents a base frontend message authenticator.

func NewBaseAuthenticator

func NewBaseAuthenticator() *BaseAuthenticator

NewBaseAuthenticator returns a base frontend message authenticator.

func (*BaseAuthenticator) Authenticate

func (executor *BaseAuthenticator) Authenticate(*Conn, *message.Startup) (message.Response, error)

Authenticate authenticates the connection with the startup message.

type BaseBulkExecutor added in v1.0.0

type BaseBulkExecutor struct {
}

BaseBulkExecutor represents a base bulk message executor.

func NewBaseBulkExecutor added in v1.0.0

func NewBaseBulkExecutor() *BaseBulkExecutor

NewBaseBulkExecutor returns a base frontend message executor.

func (*BaseBulkExecutor) Copy added in v1.0.0

func (executor *BaseBulkExecutor) Copy(*Conn, *query.Copy, *CopyStream) (message.Responses, error)

Copy handles a COPY query.

type BaseErrorHandler added in v1.1.0

type BaseErrorHandler struct {
}

BaseErrorHandler represents a base error handler.

func NewBaseErrorHandler added in v1.1.0

func NewBaseErrorHandler() *BaseErrorHandler

NewBaseErrorHandler returns a new BaseErrorHandler.

func (*BaseErrorHandler) ParserError added in v1.1.0

func (executor *BaseErrorHandler) ParserError(conn *Conn, q string, err error) (message.Responses, error)

ParserError handles a parser error.

type BaseExecutor

BaseExecutor represents a base frontend message executor.

func NewBaseExecutor

func NewBaseExecutor() *BaseExecutor

NewBaseExecutor returns a base frontend message executor.

func (*BaseExecutor) SetAuthenticator

func (executor *BaseExecutor) SetAuthenticator(at Authenticator)

SetAuthenticator sets a user authenticator.

func (*BaseExecutor) SetBulkExecutor added in v1.0.0

func (executor *BaseExecutor) SetBulkExecutor(be BulkExecutor)

SetBulkExecutor sets a user bulk executor.

func (*BaseExecutor) SetErrorHandler added in v1.1.0

func (executor *BaseExecutor) SetErrorHandler(eh ErrorHandler)

SetErrorHandler sets a user error handler.

func (*BaseExecutor) SetQueryExecutor

func (executor *BaseExecutor) SetQueryExecutor(qe QueryExecutor)

SetQueryExecutor sets a user query executor.

func (*BaseExecutor) SetStartupHandler added in v1.0.0

func (executor *BaseExecutor) SetStartupHandler(sh StartupHandler)

SetStartupHandler sets a user startup handler.

type BaseProtocolExecutor

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

BaseProtocolExecutor represents a base frontend message executor.

func NewBaseProtocolExecutor

func NewBaseProtocolExecutor() *BaseProtocolExecutor

NewBaseProtocolExecutor returns a base frontend message executor.

func (*BaseProtocolExecutor) Authenticate

func (executor *BaseProtocolExecutor) Authenticate(*Conn, *message.Startup) (message.Response, error)

Authenticate authenticates the connection with the startup message.

func (*BaseProtocolExecutor) BackendKeyData

func (executor *BaseProtocolExecutor) BackendKeyData(*Conn) (message.Response, error)

BackendKeyData returns the backend key data.

func (*BaseProtocolExecutor) ParameterStatuses added in v1.0.1

func (executor *BaseProtocolExecutor) ParameterStatuses(*Conn) (message.Responses, error)

ParameterStatuses returns the parameter statuses.

type BaseQueryExecutor

type BaseQueryExecutor struct {
}

BaseQueryExecutor represents a base query message executor.

func NewBaseQueryExecutor

func NewBaseQueryExecutor() *BaseQueryExecutor

NewBaseQueryExecutor returns a base frontend message executor.

func (*BaseQueryExecutor) CreateDatabase

func (executor *BaseQueryExecutor) CreateDatabase(*Conn, *query.CreateDatabase) (message.Responses, error)

CreateDatabase handles a CREATE DATABASE query.

func (*BaseQueryExecutor) CreateIndex

func (executor *BaseQueryExecutor) CreateIndex(*Conn, *query.CreateIndex) (message.Responses, error)

CreateIndex handles a CREATE INDEX query.

func (*BaseQueryExecutor) CreateTable

func (executor *BaseQueryExecutor) CreateTable(*Conn, *query.CreateTable) (message.Responses, error)

CreateTable handles a CREATE TABLE query.

func (*BaseQueryExecutor) Delete

func (executor *BaseQueryExecutor) Delete(*Conn, *query.Delete) (message.Responses, error)

Delete handles a DELETE query.

func (*BaseQueryExecutor) DropDatabase

func (executor *BaseQueryExecutor) DropDatabase(*Conn, *query.DropDatabase) (message.Responses, error)

DropDatabase handles a DROP DATABASE query.

func (*BaseQueryExecutor) DropTable

func (executor *BaseQueryExecutor) DropTable(*Conn, *query.DropTable) (message.Responses, error)

DropIndex handles a DROP INDEX query.

func (*BaseQueryExecutor) Insert

func (executor *BaseQueryExecutor) Insert(*Conn, *query.Insert) (message.Responses, error)

Insert handles a INSERT query.

func (*BaseQueryExecutor) Select

func (executor *BaseQueryExecutor) Select(*Conn, *query.Select) (message.Responses, error)

Select handles a SELECT query.

func (*BaseQueryExecutor) Update

func (executor *BaseQueryExecutor) Update(*Conn, *query.Update) (message.Responses, error)

Update handles a UPDATE query.

type BulkExecutor added in v0.9.1

type BulkExecutor interface {
	// Copy handles a COPY query.
	Copy(*Conn, *query.Copy, *CopyStream) (message.Responses, error)
}

BulkExecutor defines a executor interface for bulk operations.

type Config

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

Config stores server configuration parammeters.

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig returns a default configuration instance.

func (*Config) Address added in v1.0.0

func (config *Config) Address() string

Address returns a listen address from the configuration.

func (*Config) Port

func (config *Config) Port() int

Port returns a listen port from the configuration.

func (*Config) SetAddress added in v1.0.0

func (config *Config) SetAddress(addr string)

SetAddress sets a listen address to the configuration.

func (*Config) SetPort

func (config *Config) SetPort(port int)

SetPort sets a listen port to the configuration.

type Conn

type Conn struct {
	tracer.Context

	PreparedQueryMap
	// contains filtered or unexported fields
}

Conn represents a connection of PostgreSQL binary protocol.

func NewConnWith

func NewConnWith(c net.Conn, opts ...ConnOption) *Conn

NewConnWith returns a connection with a raw connection.

func (*Conn) Conn

func (conn *Conn) Conn() net.Conn

Conn returns the raw connection.

func (*Conn) Database added in v1.0.0

func (conn *Conn) Database() string

Database returns the database name.

func (*Conn) SetDatabase added in v1.0.0

func (conn *Conn) SetDatabase(db string)

SetDatabase sets the database name.

func (*Conn) SpanContext

func (conn *Conn) SpanContext() tracer.Context

SpanContext returns the tracer span context of the connection.

func (*Conn) Timestamp

func (conn *Conn) Timestamp() time.Time

Timestamp returns the creation time of the connection.

type ConnOption

type ConnOption = func(*Conn)

ConnOption represents a connection option.

type CopyStream added in v0.9.1

type CopyStream struct {
	*message.MessageReader
}

CopyStream represents a copy stream.

func NewCopyStreamWithReader added in v0.9.1

func NewCopyStreamWithReader(reader *message.MessageReader) *CopyStream

NewCopyStreamWithReader returns a new copy stream with the specified reader.

func (*CopyStream) CopyData added in v0.9.1

func (stream *CopyStream) CopyData() (*message.CopyData, error)

CopyData returns a copy data message.

func (*CopyStream) Next added in v0.9.1

func (stream *CopyStream) Next() (bool, error)

Next returns true if the next message is available.

type DDOExecutor

type DDOExecutor interface {
	// CreateDatabase handles a CREATE DATABASE query.
	CreateDatabase(*Conn, *query.CreateDatabase) (message.Responses, error)
	// CreateTable handles a CREATE TABLE query.
	CreateTable(*Conn, *query.CreateTable) (message.Responses, error)
	// CreateIndex handles a CREATE INDEX query.
	CreateIndex(*Conn, *query.CreateIndex) (message.Responses, error)
	// DropDatabase handles a DROP DATABASE query.
	DropDatabase(*Conn, *query.DropDatabase) (message.Responses, error)
	// DropIndex handles a DROP INDEX query.
	DropTable(*Conn, *query.DropTable) (message.Responses, error)
}

DDOExecutor defines a executor interface for DDO (Data Definition Operations).

type DMOExecutor

type DMOExecutor interface {
	// Insert handles a INSERT query.
	Insert(*Conn, *query.Insert) (message.Responses, error)
	// Select handles a SELECT query.
	Select(*Conn, *query.Select) (message.Responses, error)
	// Update handles a UPDATE query.
	Update(*Conn, *query.Update) (message.Responses, error)
	// Delete handles a DELETE query.
	Delete(*Conn, *query.Delete) (message.Responses, error)
}

DMOExecutor defines a executor interface for DMO (Data Manipulation Operations).

type ErrorHandler added in v1.1.0

type ErrorHandler interface {
	ParserError(*Conn, string, error) (message.Responses, error)
}

ErrorHandler represents a user error handler.

type Executor

type Executor interface {
	Authenticator
	StartupHandler
	QueryExecutor
	ErrorHandler
	// SetAuthenticator sets a user authenticator.
	SetAuthenticator(Authenticator)
	// SetStartupHandler sets a user startup handler.
	SetStartupHandler(StartupHandler)
	// SetQueryExecutor sets a user query executor.
	SetQueryExecutor(QueryExecutor)
	// SetQueryExecutor sets a user query executor.
	SetErrorHandler(ErrorHandler)
}

Executor represents a frontend message executor.

type PreparedQuery added in v0.9.1

type PreparedQuery = message.Parse

PreparedQuery represents a prepared query.

type PreparedQueryMap added in v0.9.1

type PreparedQueryMap map[string]*PreparedQuery

PreparedQueryMap represents a prepared query map.

func NewPreparedQueryMap added in v0.9.1

func NewPreparedQueryMap() PreparedQueryMap

NewPreparedQueryMap returns a new prepared query map.

func (PreparedQueryMap) PreparedQuery added in v0.9.1

func (queries PreparedQueryMap) PreparedQuery(name string) (*PreparedQuery, error)

PreparedQuery returns a prepared query.

func (PreparedQueryMap) SetPreparedQuery added in v0.9.1

func (queries PreparedQueryMap) SetPreparedQuery(query *PreparedQuery) error

SetPreparedQuery sets a prepared query.

type QueryExecutor

type QueryExecutor interface {
	DDOExecutor
	DMOExecutor
}

QueryExecutor represents a user query message executor.

type Server

type Server struct {
	*Config
	tracer.Tracer

	Executor
	// contains filtered or unexported fields
}

Server represents a PostgreSQL protocol server.

func NewServer

func NewServer() *Server

NewServer returns a new server instance.

func (*Server) Restart

func (server *Server) Restart() error

Restart restarts the server.

func (*Server) SetTracer

func (server *Server) SetTracer(t tracer.Tracer)

SetTracer sets a tracing tracer.

func (*Server) Start

func (server *Server) Start() error

Start starts the server.

func (*Server) Stop

func (server *Server) Stop() error

Stop stops the server.

type StartupHandler added in v1.0.0

type StartupHandler interface {
	StatusHandler
}

StartupHandler represents a backend protocol message handler.

type StatusHandler

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

StatusHandler represents a backend status message handler.

Directories

Path Synopsis
encoding

Jump to

Keyboard shortcuts

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