postgres

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2020 License: MIT Imports: 12 Imported by: 0

README

PostgreSQL module (for Helium) provides you connection to PostgreSQL server

Codecov Build Status Report GitHub release Sourcegraph GitHub

Module provides you connection to PostgreSQL server

  • *pg.DB is a database handle representing a pool of zero or more underlying connections. It's safe for concurrent use by multiple goroutines

Configuration:

  • yaml example
posgres:
    hostname: string
    username: string
    password: string
    database: string
    debug: bool
    pool_size: int
    options: # optional
      host: string
      sslkey: string
      sslmode: string
      sslcert: string
      sslrootcert: string
  • env example
POSTGRES_HOSTNAME=string
POSTGRES_USERNAME=string
POSTGRES_PASSWORD=string
POSTGRES_DATABASE=string
POSTGRES_DEBUG=bool
POSTGRES_POOL_SIZE=int
POSTGRES_OPTIONS_HOST=string
POSTGRES_OPTIONS_SSLKEY=string
POSTGRES_OPTIONS_SSLMODE=string
POSTGRES_OPTIONS_SSLCERT=string
POSTGRES_OPTIONS_SSLROOTCERT=string

Documentation

Index

Constants

View Source
const (
	// ErrPemParse when couldn't parse pem in sslrootcert
	ErrPemParse = Error("couldn't parse pem in sslrootcert")
	// ErrEmptyConfig when given empty options
	ErrEmptyConfig = Error("database empty config")
	// ErrEmptyLogger when logger not initialized
	ErrEmptyLogger = Error("database empty logger")
	// ErrSSLKeyHasWorldPermissions when pk permissions no u=rw (0600) or less
	ErrSSLKeyHasWorldPermissions = Error("private key file has group or world access. Permissions should be u=rw (0600) or less")
)

Variables

View Source
var (
	// Module is default connection to PostgreSQL
	Module = module.Module{
		{Constructor: NewDefaultConfig},
		{Constructor: NewConnection},
	}
)

Functions

func NewConnection

func NewConnection(cfg *Config, l *zap.Logger) (db *pg.DB, err error)

NewConnection returns database connection

Types

type Config

type Config struct {
	Hostname string
	Username string
	Password string
	Database string
	Debug    bool
	PoolSize int
	Options  map[string]string
}

Config alias

func NewDefaultConfig

func NewDefaultConfig(v *viper.Viper) (*Config, error)

NewDefaultConfig returns connection config

type Error added in v0.3.0

type Error string

Error is constant error

func (Error) Error added in v0.3.0

func (e Error) Error() string

Error implementation

type Hook

type Hook struct {
	StartAt time.Time
	Before  func(context.Context, *pg.QueryEvent) (context.Context, error)
	After   func(context.Context, *pg.QueryEvent) error
}

Hook is a simple implementation of pg.QueryHook

func (Hook) AfterQuery

func (h Hook) AfterQuery(ctx context.Context, e *pg.QueryEvent) error

AfterQuery callback

func (*Hook) BeforeQuery

func (h *Hook) BeforeQuery(ctx context.Context, e *pg.QueryEvent) (context.Context, error)

BeforeQuery callback

Jump to

Keyboard shortcuts

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