pgutil

package module
v0.0.0-...-4c8aab9 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2017 License: MIT Imports: 11 Imported by: 6

README

pgutil

GoLang PostgreSQL utilities I've written and collected from various public sources on the web.

// Database connection info
type DbInfo struct {
    DbName string
    DbHost string
    DbPort int32
    DbUser string
    DbPass string
    DbOptions string
}
/*
 * Populates the database connection info from environment variables and/or runtime flags.
 * flag.Parse() is called, so define any other program flags before calling this.
 */
func (dbInfo *DbInfo) Populate() {
/*
 * Opens a postgreSQL database connection using the DbInfo instance
 */
func (dbInfo *DbInfo) Open() (*sql.DB, error)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DbUsage

func DbUsage()

DbUsage provides a model for adding to your own database executable

func PgPassword

func PgPassword(user string) string

PgPassword parses the ~/.pgpass file and gets the password for the given user. The current implementation ignores the location field.

func QueryStrings

func QueryStrings(db *sql.DB, query string) (chan map[string]string, []string)

QueryStrings returns row maps (keyed by the column name) in a channel. Dynamically converts each column value to a SQL string value. See http://stackoverflow.com/questions/23507531/is-golangs-sql-package-incapable-of-ad-hoc-exploratory-queries

Types

type DbInfo

type DbInfo struct {
	DbName    string
	DbHost    string
	DbPort    int32
	DbUser    string
	DbPass    string
	DbSchema  string
	DbOptions string
}

DbInfo contains database connection info

func (*DbInfo) ConnectionString

func (dbInfo *DbInfo) ConnectionString() string

ConnectionString returns the string needed by the postgres driver library to connect

func (*DbInfo) Open

func (dbInfo *DbInfo) Open() (*sql.DB, error)

Open opens a postgreSQL database connection using the DbInfo instance

func (*DbInfo) Populate

func (dbInfo *DbInfo) Populate() (verFlag, helpFlag bool)

Populate populates the database connection info from environment variables or runtime flags. This calls flag.Parse(), so define any other program flags before calling this.

It is assumed that -V is the version flag, and -? is the help flag. These are assumed so we don't continue processing DB flags if one of these is set.

Jump to

Keyboard shortcuts

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