postgres

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2019 License: MIT Imports: 6 Imported by: 0

README

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

Codecov CircleCI (all branches) Report GitHub release 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:
    address: string
    username: string
    password: string
    database: string
    debug: bool
    pool_size: int
  • env example
POSTGRES_ADDRESS=string
POSTGRES_USERNAME=string
POSTGRES_PASSWORD=string
POSTGRES_DATABASE=string
POSTGRES_DEBUG=bool
POSTGRES_POOL_SIZE=int

Documentation

Index

Constants

This section is empty.

Variables

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

	// ErrEmptyConfig when given empty options
	ErrEmptyConfig = errors.New("database empty config")
	// ErrEmptyLogger when logger not initialized
	ErrEmptyLogger = errors.New("database empty logger")
)

Functions

func NewConnection

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

NewConnection returns database connection

Types

type Config

type Config = struct {
	Addr     string
	User     string
	Password string
	Database string
	Debug    bool
	PoolSize int
	Logger   *zap.SugaredLogger
}

Config alias

func NewDefaultConfig

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

NewDefaultConfig returns connection config

type Hook

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

Hook is a simple implementation of pg.QueryHook

func (Hook) AfterQuery

func (h Hook) AfterQuery(e *pg.QueryEvent)

AfterQuery callback

func (*Hook) BeforeQuery

func (h *Hook) BeforeQuery(e *pg.QueryEvent)

BeforeQuery callback

Jump to

Keyboard shortcuts

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