pgutil

package
v0.0.0-...-6de94a8 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorLogArg = "error"
)

Variables

This section is empty.

Functions

func ExecSQL

func ExecSQL(ctx context.Context, sql string) (err error)

func ExecSQLFile

func ExecSQLFile(ctx context.Context, filename string) (err error)

func InitializeDB

func InitializeDB(ctx context.Context, connStr string, dbName ...string) (err error)

func NewPGBool

func NewPGBool(b bool) pgtype.Bool

func NewPGText

func NewPGText(s string) pgtype.Text

func NewPGTimestamp

func NewPGTimestamp(t time.Time) pgtype.Timestamp

func SetDB

func SetDB(newDB *DB)

Types

type DB

type DB struct {
	Querier
	// contains filtered or unexported fields
}

func GetDB

func GetDB() *DB

func NewDB

func NewDB(conn *pgx.Conn) (db *DB)

NewDB creates a new DB

func (*DB) Close

func (db *DB) Close(ctx context.Context) (err error)

func (*DB) Execute

func (db *DB) Execute(ctx context.Context, query string, args ...interface{}) (pgconn.CommandTag, error)

func (*DB) Query

func (db *DB) Query(ctx context.Context, query string, args ...interface{}) (pgx.Rows, error)

Query sends a query to the server and returns a list of rows as pgx.Rows to read the results. Only errors encountered sending the query and initializing Rows will be returned. Err() on the returned Rows must be checked after the Rows is closed to determine if the query executed successfully.

The returned Rows must be closed before the connection can be used again. It is safe to attempt to read from the returned Rows even if an error is returned. The error will be the available in rows.Err() after rows are closed. It is allowed to ignore the error returned from Query and handle it in Rows.

It is possible for a call of FieldDescriptions on the returned Rows to return nil even if the Query call did not return an error.

It is possible for a query to return one or more rows before encountering an error. In most cases the rows should be collected before processing rather than processed while receiving each row. This avoids the possibility of the application processing rows from a query that the server rejected. The CollectRows function is useful here.

func (*DB) QueryRow

func (db *DB) QueryRow(ctx context.Context, query string, args ...interface{}) pgx.Row

QueryRow is a convenience wrapper over Query. Any error that occurs while querying is deferred until calling Scan on the returned Row. That pgx.Row will error with pgx.ErrNoRows if no rows are returned.

type Querier

type Querier interface {
}

type SQLSnippet

type SQLSnippet struct {
	Message string
	Query   string
	Error   error
}

Jump to

Keyboard shortcuts

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