Categorygithub.com/imneov/PostgreCRD
modulepackage
0.0.0-20231025143031-ac1779c1cb7f
Repository: https://github.com/imneov/postgrecrd.git
Documentation: pkg.go.dev

# README

PSQL wire protocol 🔌

CI Go Reference Latest release Go Report Card

Note: this work is a fork of [jeroenrinzema/psql-wire](https://github. com/jeroenrinzema/psql-wire).

A pure Go PostgreSQL server wire protocol implementation. Build your own PostgreSQL server within a few lines of code. This project attempts to make it as straight forward as possible to set-up and configure your own PSQL server. Feel free to check out the examples directory for various ways on how to configure/set-up your own server.

🚧 This project does not include a PSQL parser. Please check out other projects such as auxten/postgresql-parser to parse PSQL SQL queries.

package main

import (
	"context"
	"fmt"

	wire "github.com/imneov/PostgreCRD"
)

func main() {
	wire.ListenAndServe("127.0.0.1:5432", handler)
}

func handler(ctx context.Context, query string) (wire.PreparedStatementFn, []oid.Oid, wire.Columns, error) {
	fmt.Println(query)

	statement := func(ctx context.Context, writer wire.DataWriter, parameters []string) error {
		return writer.Complete("OK")
	}

	return statement, nil, nil, nil
}

🚧 When wanting to debug issues and or inspect the PostgreSQL wire protocol please check out the psql-proxy cli

Contributing

Thank you for your interest in contributing to psql-wire! Check out the open projects and/or issues and feel free to join any ongoing discussion. Feel free to checkout the open TODO's within the project.

Everyone is welcome to contribute, whether it's in the form of code, documentation, bug reports, feature requests, or anything else. We encourage you to experiment with the project and make contributions to help evolve it to meet your needs!

See the contributing guide for more details.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

AuthenticatedUsername returns the username of the authenticated user of the given connection context.
Certificates sets the given TLS certificates to be used to initialize a secure connection between the front-end (client) and back-end (server).
ClearTextPassword announces to the client to authenticate by sending a clear text password and validates if the provided username and password (received inside the client parameters) are valid.
ClientAuth sets the given Client Auth to be used, by the server, to verify a secure connection between the front-end (client) and back-end (server).
ClientCAs sets the given Client CAs to be used, by the server, to verify a secure connection between the front-end (client) and back-end (server).
ClientParameters returns the connection parameters if it has been set inside the given context.
CloseConn sets the close connection handle inside the given server instance.
ErrorCode writes a error message as response to a command with the given severity and error message.
ExtendTypes provides the ability to extend the underlying connection types.
GlobalParameters sets the server parameters which are send back to the front-end (client) once a handshake has been established.
IsSuperUser checks whether the given connection context is a super user.
ListenAndServe opens a new Postgres server using the given address and default configurations.
Logger sets the given zap logger as the default logger for the given server.
MessageBufferSize sets the message buffer size which is allocated once a new connection gets constructed.
NewDataWriter constructs a new data writer using the given context and buffer.
NewErrUnimplementedMessageType is called whenever a unimplemented message type is send.
NewErrUnkownStatement is returned whenever no executable has been found for the given name.
NewServer constructs a new Postgres server using the given address and server options.
ParseParameters attempts ot parse the parameters in the given string and returns the expected parameters.
Portals sets the portals cache used to cache statements for later use.
ServerParameters returns the connection parameters if it has been set inside the given context.
Session sets the given session handler within the underlying server.
SessionAuthStrategy sets the given authentication strategy within the given server.
Statements sets the statement cache used to cache statements for later use.
TerminateConn sets the terminate connection handle inside the given server instance.
TypeInfo returns the Postgres type connection info if it has been set inside the given context.
Version sets the PostgreSQL version for the server which is send back to the front-end (client) once a handshake has been established.

# Constants

BinaryFormat is an alternative, binary, encoding.
At present there is a hard-wired set of parameters for which ParameterStatus will be generated.
At present there is a hard-wired set of parameters for which ParameterStatus will be generated.
At present there is a hard-wired set of parameters for which ParameterStatus will be generated.
At present there is a hard-wired set of parameters for which ParameterStatus will be generated.
At present there is a hard-wired set of parameters for which ParameterStatus will be generated.
At present there is a hard-wired set of parameters for which ParameterStatus will be generated.
At present there is a hard-wired set of parameters for which ParameterStatus will be generated.
At present there is a hard-wired set of parameters for which ParameterStatus will be generated.
At present there is a hard-wired set of parameters for which ParameterStatus will be generated.
TextFormat is the default, text format.

# Variables

ErrClosedWriter is thrown when the data writer has been closed.
ErrDataWritten is thrown when an empty result is attempted to be send to the client while data has already been written.
QueryParameters represents a regex which could be used to identify and lookup parameters defined inside a given query.

# Structs

Column represents a table column and its attributes such as name, type and encode formatter.
No description provided by the author
No description provided by the author
Server contains options for listening to an address.
No description provided by the author

# Interfaces

DataWriter represents a writer interface for writing columns and data rows using the Postgres wire to the connected client.
PortalCache represents a cache which could be used to bind and execute prepared statements with parameters.
StatementCache represents a cache which could be used to store and retrieve prepared statements bound to a name.

# Type aliases

AuthStrategy represents a authentication strategy used to authenticate a user.
No description provided by the author
Columns represent a collection of columns.
FormatCode represents the encoding format of a given column.
FormatEncoder represents a format code wire encoder.
OptionFn options pattern used to define and set options for the given PostgreSQL server.
Parameters represents a parameters collection of parameter status keys and their values.
ParameterStatus represents a metadata key that could be defined inside a server/client metadata definition.
ParseFn parses the given query and returns a prepared statement which could be used to execute at a later point in time.
PreparedStatementFn represents a query of which a statement has been prepared.
SessionHandler represents a wrapper function defining the state of a single session.