db

package
v0.0.0-...-779d28c Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DSN

func DSN(opts Opts) string

DSN constructs a postgres-compatible connection URI.

Types

type Client

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

Client to PostgreSQL server.

func New

func New(ctx context.Context, opts Opts) (*Client, error)

New instantiates and returns a new DB.

func (*Client) CheckConnection

func (c *Client) CheckConnection(ctx context.Context) error

CheckConnection acquires a connection from the pool and executes an empty sql statement over it.

func (*Client) Select

func (c *Client) Select(ctx context.Context, dest interface{}, sql string, args ...interface{}) error

Select executes a statement that fetches rows in a transaction.

func (*Client) SelectPgLocks

func (db *Client) SelectPgLocks(ctx context.Context) ([]*model.PgLock, error)

SelectPgLocks selects stats on locks held.

func (*Client) SelectPgStatActivity

func (db *Client) SelectPgStatActivity(ctx context.Context) ([]*model.PgStatActivity, error)

SelectPgStatActivity selects stats on user tables.

func (*Client) SelectPgStatStatements

func (db *Client) SelectPgStatStatements(ctx context.Context) ([]*model.PgStatStatement, error)

SelectPgStatStatements selects stats on user tables.

func (*Client) SelectPgStatUserIndexes

func (db *Client) SelectPgStatUserIndexes(ctx context.Context) ([]*model.PgStatUserIndex, error)

SelectPgStatUserIndexes selects stats on user indexes.

func (*Client) SelectPgStatUserTables

func (db *Client) SelectPgStatUserTables(ctx context.Context) ([]*model.PgStatUserTable, error)

SelectPgStatUserTables selects stats on user tables.

func (*Client) SelectPgStatioUserIndexes

func (db *Client) SelectPgStatioUserIndexes(ctx context.Context) ([]*model.PgStatioUserIndex, error)

SelectPgStatioUserIndexes selects stats on user indexes.

func (*Client) SelectPgStatioUserTables

func (db *Client) SelectPgStatioUserTables(ctx context.Context) ([]*model.PgStatioUserTable, error)

SelectPgStatioUserTables selects stats on user tables.

type Opts

type Opts struct {
	//
	Host            string `long:"postgres_host"     env:"POSTGRES_HOST"     default:"localhost" description:"Postgres host"`
	Port            int    `long:"postgres_port"     env:"POSTGRES_PORT"     default:"5432"     description:"Postgres port"`
	User            string `long:"postgres_user"     env:"POSTGRES_USER"     default:"postgres" description:"Postgres username"`
	Password        string `long:"postgres_password" env:"POSTGRES_PASSWORD" default:"postgres" description:"Postgres password"`
	Database        string `long:"postgres_database" env:"POSTGRES_DATABASE" default:"postgres" description:"Postgres database"`
	AuthMechanism   string `` /* 175-byte string literal not displayed */
	ApplicationName string `long:"application_name" env:"APP_NAME" required:"true"`
	// Connection parameters.
	ConnectTimeout       time.Duration `long:"connect_timeout" env:"CONNECT_TIMEOUT" default:"10s" description:"Postgres connection timeout"`
	MaxConnectionRetries int           `` /* 239-byte string literal not displayed */
	// Client connection optional parameters.
	DefaultIsolationLevel           string        `` /* 215-byte string literal not displayed */
	StatementTimeout                time.Duration `` /* 274-byte string literal not displayed */
	LockTimeout                     time.Duration `` /* 489-byte string literal not displayed */
	IdleInTransactionSessionTimeout time.Duration `` /* 446-byte string literal not displayed */
	// Transaction options.
	TotalTransactionTimeout      time.Duration `` /* 202-byte string literal not displayed */
	InitialTransactionRetryDelay time.Duration `` /* 180-byte string literal not displayed */
	BaseTransactionRetryDelay    time.Duration `` /* 166-byte string literal not displayed */
	MaxTransactionAttempts       int           `` /* 194-byte string literal not displayed */
	ReadOnly                     bool          `` /* 128-byte string literal not displayed */
	// pgxpool.ConnConfig
	PoolMaxConns          int           `long:"pool_max_conns" env:"MAX_CONNS" default:"10" description:"Max open connections to the database"`
	PoolMinConns          int           `long:"pool_min_conns" env:"MIN_CONNS" default:"2" description:"Min open connections to the database"`
	PoolMaxConnLifetime   time.Duration `` /* 152-byte string literal not displayed */
	PoolMaxConnIdleTime   time.Duration `` /* 156-byte string literal not displayed */
	PoolHealthCheckPeriod time.Duration `` /* 169-byte string literal not displayed */
	// pgx.ConnConfig
	StatementCacheCapacity int    `` /* 211-byte string literal not displayed */
	StatementCacheMode     string `` /* 459-byte string literal not displayed */
}

Opts specify the configuration for a postgres client.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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