...

Package sql

import "golang.conradwood.net/go-easyops/sql"
Overview
Index

Overview ▾

Package sql provides safe and managed access to (postgres) databases

Constants

const (
    DEFAULT_MAX_QUERY_MILLIS = 3000
)

func IsSQLSafe

func IsSQLSafe(txt string) bool

**** // Helpers /********* returns true if this string is sql safe (no special characters

type DB

type DB struct {
    MaxQueryTimeout int
    // contains filtered or unexported fields
}

func Open

func Open() (*DB, error)

call this once when you startup and cache the result only if there is an error you'll need to retry

func OpenWithInfo

func OpenWithInfo(dbhost, dbdb, dbuser, dbpw string) (*DB, error)

func (*DB) CheckDuplicateRowError

func (d *DB) CheckDuplicateRowError(err error) bool

func (*DB) Conn

func (d *DB) Conn(ctx context.Context) (*sql.Conn, error)

func (*DB) ExecContext

func (d *DB) ExecContext(ctx context.Context, name string, query string, args ...interface{}) (sql.Result, error)

"name" will be used to provide timing information as prometheus metric.

func (*DB) ExecContextQuiet

func (d *DB) ExecContextQuiet(ctx context.Context, name string, query string, args ...interface{}) (sql.Result, error)

func (*DB) GetDatabaseName

func (d *DB) GetDatabaseName() string

func (*DB) GetFailureCounter

func (d *DB) GetFailureCounter() *utils.SlidingAverage

func (*DB) QueryContext

func (d *DB) QueryContext(ctx context.Context, name string, query string, args ...interface{}) (*sql.Rows, error)

"name" will be used to provide timing information as prometheus metric.

func (*DB) QueryRowContext

func (d *DB) QueryRowContext(ctx context.Context, name string, query string, args ...interface{}) *sql.Row

discouraged use. QueryRow() does not provide an error on the query, nor do we get a good timing value. Use QueryContext() instead.

type PoolSizeCollector

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

func NewPoolSizeCollector

func NewPoolSizeCollector() *PoolSizeCollector

func (*PoolSizeCollector) Collect

func (c *PoolSizeCollector) Collect(ch chan<- pm.Metric)

func (*PoolSizeCollector) Describe

func (c *PoolSizeCollector) Describe(ch chan<- *pm.Desc)