postgres

package
v0.0.0-...-fec4e2b Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2022 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ENV_VAR_NAME_DISABLED             = "LONG_QUERY_LOGGING_OFF"
	ENV_VAR_NAME_THRESHOLD            = "LONG_QUERY_THRESHOLD_SECS"
	DEFAULT_LONG_QUERY_THRESHOLD_SECS = 10
)
View Source
const DefaultStatementTimeout = 5 * time.Minute

Variables

View Source
var (
	LongQueryThresholdSecs int
	LoggingDisabled        bool
	Logger                 *logrus.Entry
)

Functions

This section is empty.

Types

type DB

type DB struct {
	*sqlx.DB
}

DB exposes all the methods available on the *sqlx.DB struct

func NewPostgresDB

func NewPostgresDB(opts *PostgresDBOpts) (DB, error)

func (DB) Begin

func (db DB) Begin() (*Tx, error)

func (DB) Beginx

func (db DB) Beginx() (*Tx, error)

func (DB) Get

func (db DB) Get(dest interface{}, query string, args ...interface{}) error

func (DB) NamedExec

func (db DB) NamedExec(query string, arg interface{}) (sql.Result, error)

func (DB) Query

func (db DB) Query(query string, args ...interface{}) (*sql.Rows, error)

func (DB) QueryRow

func (db DB) QueryRow(query string, args ...interface{}) *sql.Row

func (DB) QueryRowx

func (db DB) QueryRowx(query string, args ...interface{}) *sqlx.Row

func (DB) Queryx

func (db DB) Queryx(query string, args ...interface{}) (*sqlx.Rows, error)

func (*DB) ResetDB

func (db *DB) ResetDB()

Many packages use the same schema, this function knows which order to clear out tables so each package doesn't need to know (given foreign key constraints, etc)

func (*DB) ResetTables

func (db *DB) ResetTables()

Many packages use the same schema, this function knows which order to clear out tables so each package doesn't need to know (given foreign key constraints, etc)

func (DB) Select

func (db DB) Select(dest interface{}, query string, args ...interface{}) error

type PostgresDBOpts

type PostgresDBOpts struct {
	Host             string
	Port             string
	User             string
	Password         string
	Database         string
	Driver           string
	MaxOpenConns     int
	MaxIdleConns     int
	StatementTimeout time.Duration
}

func LocalOpts

func LocalOpts() *PostgresDBOpts

func MustGetOpts

func MustGetOpts() *PostgresDBOpts

MustGetOpts gets database configuration from the environment. Panics if any configuration items are missing.

func MustGetOptsWithMaxConns

func MustGetOptsWithMaxConns(maxOpenConns int, maxIdleConns int) *PostgresDBOpts

type Querier

type Querier interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Select(dest interface{}, query string, args ...interface{}) error
	SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	Get(dest interface{}, query string, args ...interface{}) error
	Rebind(query string) string
	QueryRow(query string, args ...interface{}) *sql.Row
	QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
}

Querier is an interface which is implemented by both *sqlx.DB and *sqlx.Tx

type Timer

type Timer struct {
	Start       time.Time
	FuncName    string
	QueryString string
	Args        []interface{}
}

func NewTimer

func NewTimer(funcName string, query string, args []interface{}) *Timer

func (*Timer) Stop

func (t *Timer) Stop()

type Tx

type Tx struct {
	*sqlx.Tx
}

Tx exposes all the methods available on the *sqlx.Tx struct

func (Tx) Get

func (tx Tx) Get(dest interface{}, query string, args ...interface{}) error

func (Tx) NamedExec

func (tx Tx) NamedExec(query string, arg interface{}) (sql.Result, error)

func (Tx) Query

func (tx Tx) Query(query string, args ...interface{}) (*sql.Rows, error)

func (Tx) QueryRow

func (tx Tx) QueryRow(query string, args ...interface{}) *sql.Row

func (Tx) QueryRowx

func (tx Tx) QueryRowx(query string, args ...interface{}) *sqlx.Row

func (Tx) Queryx

func (tx Tx) Queryx(query string, args ...interface{}) (*sqlx.Rows, error)

func (Tx) Select

func (tx Tx) Select(dest interface{}, query string, args ...interface{}) error

Jump to

Keyboard shortcuts

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