postgres

package module
v0.1.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const ErrCodeUniqueViolation = "23505"

Variables

This section is empty.

Functions

func BuildConnectionURI

func BuildConnectionURI(cc Config) string

BuildConnectionURI builds a connection string for lib/pq from Config. If a missing or invalid field is provided, an error is returned.

func GetErrCodeUniqueViolationKV

func GetErrCodeUniqueViolationKV(err *pq.Error) (string, string)

func RandomDBName

func RandomDBName(prefix string) string

RandomDBName generates a Postgres database name with a provided prefix and random suffix in order to avoid collisions and race conditions in parallel tests.

This uses a pseudorandom integer rather than a UUID to avoid hyphens in the database name. Postgres database names with hyphens do not autocomplete on the psql command line, which is a pain in case you get stuck manually deleting a bunch of these.

Types

type Config

type Config struct {
	Host                  string
	Port                  int
	Username              string
	Password              string
	Database              string
	ApplicationName       string
	ConnectTimeoutSeconds int
	SSLMode               string
}

Config defines Postgres sql connection parameters

func (*Config) RegisterFlags

func (c *Config) RegisterFlags(f *flag.FlagSet)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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