postgres

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Service = dependency.Service{
	ConfigFunc: func(set dependency.FlagSet) {
		set.String("postgres-dbname", "postgres", "The name of the database to connect to")
		set.String("postgres-user", "postgres", "The name of the user to connect to the postgres db with")
		set.String("postgres-password", "", "The password to connect to the postgres database")
		set.String("postgres-host", "localhost", "The host to connect to the postgres database on")
		set.Int("postgres-port", 5432, "The port to connect to the postgres database on")
		set.String("postgres-sslmode", "disable", "What sslmode to use with the postgres database")
		set.String("postgres-fallback-application-name", "", "An application_name for postgres to fall back to if one isn't provided.")
		set.Duration("postgres-connect-timeout", 0, "Maximum wait for connection, 0 means wait indefinitely")
		set.String("postgres-sslcert", "", "Cert file location. The file must contain PEM encoded data.")
		set.String("postgres-sslkey", "", "Key file location. The file must contain PEM encoded data.")
		set.String("postgres-sslrootkey", "", "The location of the root certificate file. The file must contain PEM encoded data.")
	},
	Dependencies: fx.Provide(
		NewConfig, NewSQLX,
	),
	Constructor: NewFactory().DB,
}

Service defines the configuration and constructors required to get a postgres *sql.DB

Functions

func NewSQLX

func NewSQLX(db *sql.DB) *sqlx.DB

Types

type Config

type Config struct {
	DBName                  string
	User                    string
	Password                string
	Host                    string
	Port                    int
	SSLMode                 string
	FallbackApplicationName string
	ConnectTimeout          time.Duration
	SSLCert                 string
	SSLKey                  string
	SSLRootCert             string
}

Config defines the configuration required to create a postgres database connection

func NewConfig

func NewConfig(config dependency.ConfigGetter) Config

NewConfig creates a new instance of the configuration from app configuration

func (Config) String

func (c Config) String() string

String implements fmt.Stringer, and returns the required configuration as a libpq connection string

type Factory

type Factory struct {
	Opener func(driverName, dataSourceName string) (*sql.DB, error)
}

Factory is a type that can create

func NewFactory

func NewFactory() Factory

NewFactory creates a new instance of a Factory that can create postgres *sql.DBs

func (Factory) DB

func (f Factory) DB(config Config, check healthcheck.Handler) (*sql.DB, error)

DB creates a new instance of a postgres *sql.DB and registers it to the health check

Jump to

Keyboard shortcuts

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