db

package
v0.0.0-...-c83d288 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2018 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package db manages interaction with an underlying database store.

This package is a thin layer around pgx that provides a configuration interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ConnString     string `toml:"connection_string"`
	MaxConnections int    `toml:"max_connections"`
}

Config represents configuration details for creating a connection pool.

type ConnPool

type ConnPool struct {
	// contains filtered or unexported fields
}

Type ConnPool represents a connection pool.

func New

func New(c Config, l log.Logger) (*ConnPool, error)

New creates a new ConnPool using the given Config.

Generally only one ConnPool should be used, shared by the entire application.

func (*ConnPool) Open

func (p *ConnPool) Open() (*pgx.Conn, error)

Open acquires a connection for the caller.

Remember to Release the DB when you're done with it! Otherwise the connection will not be released back to the pool, and eventually you will run out of available connections.

func (*ConnPool) Release

func (p *ConnPool) Release(c *pgx.Conn)

Release returns the given connection back to the connection pool.

This method should be called, probably in a defer statement, before the end of any function that Opens a connection. If a connection is not released, eventually the application will run out of available connections and fail.

Jump to

Keyboard shortcuts

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