postgres

package
v0.1.33 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: CC0-1.0, CC0-1.0 Imports: 19 Imported by: 2

Documentation

Overview

Package postgres implements the keyvalue interfaces when working with PostgreSQL.

The dataSource should be in the format:

postgres://[username[:password]@]host1[:port1][,...hostN[:portN]]/database[?param1=value1&...]

If a host name begins with a slash, it specifies Unix-domain communication rather than TCP/IP communication; the value is the name of the directory in which the socket file is stored. The default behavior when host is not specified, or is empty, is to connect to a Unix-domain socket in /tmp (or whatever socket directory was specified when PostgreSQL was built). On machines without Unix-domain sockets, the default is to connect to localhost. The corresponding port number is the port to connect to at the server host, or socket file name extension for Unix-domain connections.

Valid parameters are:

  • appname The application name to identify ourselves as.
  • connect_timeout Maximum wait for connection, in seconds. Zero or not specified means wait indefinitely.
  • requiressl Whether to require connections over SSL; set to 'true' to force SSL when connecting.
  • fastcopy Whether to support PostgreSQL's COPY commands; set to 'true' to enable COPY.

Any other parameters will be ignored.

fastcopy: If enabled, the COPY command will be used to perform inserts. Note that, with the citus extension for sharded tables enabled, the COPY command opens up one connection per shard (see [http://docs.citusdata.com/en/v8.2/reference/common_errors.html]). If you run M concurrent copies into a destination with N shards, that will result in M*N connections. In this circumstance you probably want to disable the COPY command, as it is likely to exhaust the number of available connections.

Index

Constants

View Source
const DriverName = "postgres"

DriverName is the name used to register the driver.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientConfig

type ClientConfig struct {
	AppName        string   // The application name to identify ourselves via
	Hosts          []string // The hosts
	Username       string   // The user to sign in as
	Password       string   // The user's password
	PasswordSet    bool     // Is a password set?
	ConnectTimeout int      // Maximum wait for connection, in seconds
	RequireSSL     bool     // Whether or not to require SSL
	FastCopy       bool     // Whether or not to enable fast Copy
}

ClientConfig describes the configuration options we allow a user to set on a client connection.

func DefaultConfig

func DefaultConfig() *ClientConfig

DefaultConfig returns a new client configuration initialised with the default values.

The initial default value for the hosts, username, and password will be read from the environment variables

PCAS_POSTGRES_HOST = "hostname1[:port1][,...,hostnamek[:portk]]"
PCAS_POSTGRES_USERNAME = "myname"
PCAS_POSTGRES_PASSWORD = "mysecret"

respectively on package init.

Note that if PCAS_POSTGRES_PASSWORD is set but with value equal to the empty string then it still counts as a valid password, since the empty string is a valid password. You must ensure that PCAS_POSTGRES_PASSWORD is unset if you do not want to specify an initial default password.

func ParseURL

func ParseURL(s string) (*ClientConfig, string, error)

ParseURL parses the given URL into client configuration options and database name.

func SetDefaultConfig

func SetDefaultConfig(c *ClientConfig) *ClientConfig

SetDefaultConfig sets the default client configuration to c and returns the old default configuration. This change will be reflected in future calls to DefaultConfig.

func (*ClientConfig) Copy

func (c *ClientConfig) Copy() *ClientConfig

Copy returns a copy of the configuration.

func (*ClientConfig) ToPqOptions

func (c *ClientConfig) ToPqOptions(dbName string) string

ToPqOptions converts the configuration to a string of pq connection options, connecting to the given database.

func (*ClientConfig) URL

func (c *ClientConfig) URL(dbName string) string

URL returns a URL representation of the configuration, connecting to the given database.

func (*ClientConfig) Validate

func (c *ClientConfig) Validate() error

Validate validates the client configuration, returning an error if there's a problem.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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