database

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TWRRYtd    = "twrr_ytd"
	TWRRMtd    = "twrr_mtd"
	TWRRWtd    = "twrr_wtd"
	TWRROneDay = "twrr_1d"
)

Variables

View Source
var (
	ErrEmptyUserID = errors.New("userID cannot be an empty string")
)
View Source
var (
	ErrUnsupported = errors.New("unsupported function")
)

Functions

func Connect

func Connect(ctx context.Context) error

func GetUsers

func GetUsers(ctx context.Context) ([]string, error)

Get a list of users in the pvapi role

func LogOpenTransactions

func LogOpenTransactions()

LogOpenTransactions writes an INFO log for each open transaction

func SetPool

func SetPool(myPool PgxIface)

func TrxForUser

func TrxForUser(ctx context.Context, userID string) (pgx.Tx, error)

TrxForUser creates a transaction with the appropriate user set NOTE: the default use is pvapi which only has enough privileges to create new roles and switch to them. Any kind of real work must be done with a user role which limits access to only that user

Types

type PgxIface

type PgxIface interface {
	Begin(context.Context) (pgx.Tx, error)
}

type PvDbTx

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

func (*PvDbTx) Begin

func (t *PvDbTx) Begin(_ context.Context) (pgx.Tx, error)

Begin starts a pseudo nested transaction.

func (*PvDbTx) BeginFunc

func (t *PvDbTx) BeginFunc(_ context.Context, _ func(pgx.Tx) error) (err error)

BeginFunc starts a pseudo nested transaction and executes f. If f does not return an err the pseudo nested transaction will be committed. If it does then it will be rolled back.

func (*PvDbTx) Commit

func (t *PvDbTx) Commit(ctx context.Context) error

Commit commits the transaction if this is a real transaction or releases the savepoint if this is a pseudo nested transaction. Commit will return ErrTxClosed if the Tx is already closed, but is otherwise safe to call multiple times. If the commit fails with a rollback status (e.g. the transaction was already in a broken state) then ErrTxCommitRollback will be returned.

func (*PvDbTx) Conn

func (t *PvDbTx) Conn() *pgx.Conn

Conn returns the underlying *Conn that on which this transaction is executing.

func (*PvDbTx) CopyFrom

func (t *PvDbTx) CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)

func (*PvDbTx) Exec

func (t *PvDbTx) Exec(ctx context.Context, sql string, arguments ...interface{}) (commandTag pgconn.CommandTag, err error)

func (*PvDbTx) LargeObjects

func (t *PvDbTx) LargeObjects() pgx.LargeObjects

func (*PvDbTx) Prepare

func (t *PvDbTx) Prepare(ctx context.Context, name, sql string) (*pgconn.StatementDescription, error)

func (*PvDbTx) Query

func (t *PvDbTx) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)

func (*PvDbTx) QueryFunc

func (t *PvDbTx) QueryFunc(ctx context.Context, sql string, args []interface{}, scans []interface{}, f func(pgx.QueryFuncRow) error) (pgconn.CommandTag, error)

func (*PvDbTx) QueryRow

func (t *PvDbTx) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row

func (*PvDbTx) Rollback

func (t *PvDbTx) Rollback(ctx context.Context) error

Rollback rolls back the transaction if this is a real transaction or rolls back to the savepoint if this is a pseudo nested transaction. Rollback will return ErrTxClosed if the Tx is already closed, but is otherwise safe to call multiple times. Hence, a defer tx.Rollback() is safe even if tx.Commit() will be called first in a non-error condition. Any other failure of a real transaction will result in the connection being closed.

func (*PvDbTx) SendBatch

func (t *PvDbTx) SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults

Jump to

Keyboard shortcuts

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