pgxscan

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2023 License: MIT Imports: 10 Imported by: 0

README

pgxscan

Introduction

pgxscan is a simple and convenient library for working with the pgx pool driver, featuring the ability to scan results into structures and the opportunity wrap queries in transactions.

Features

Installation

Usage

Dependencies

This library uses:

License

pgxscan is available under the MIT License. See the LICENSE file for more info.

Contributing

If you have an idea or a question, just post a pull request or an issue. Every feedback is appreciated.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRecordsNotFound = errors.New("no rows in result set")
)

Functions

This section is empty.

Types

type Client

type Client interface {
	Get(ctx context.Context, dest interface{}, sql string, args ...interface{}) error
	Select(ctx context.Context, dest interface{}, sql string, args ...interface{}) error
	Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
	InTx(ctx context.Context, isoLevel pgx.TxIsoLevel, f func(ctx context.Context) error) error
	Ping(ctx context.Context) error
	Close()
}

func New

func New(ctx context.Context, config Config) (Client, error)

type Config

type Config struct {
	Host     string `json:"host" mapstructure:"host"`
	Port     string `json:"port" mapstructure:"port"`
	Name     string `json:"name" mapstructure:"name"`
	User     string `json:"user" mapstructure:"user"`
	Password string `json:"password" mapstructure:"password"`
	SSLMode  string `json:"sslMode" mapstructure:"sslMode"`

	// Query timeout, default is 5s
	QueryTimeout time.Duration `json:"queryTimeout" mapstructure:"queryTimeout"`

	// Minimum number of idle connections (inactive connections that remain open)
	PoolMinConnections string `json:"poolMinConnections" mapstructure:"poolMinConnections"`

	// Maximum number of connections
	PoolMaxConnections string `json:"poolMaxConnections" mapstructure:"poolMaxConnections"`

	// The duration for which a connection will live before being closed
	PoolMaxConnLife time.Duration `json:"poolMaxConnLife" mapstructure:"poolMaxConnLife"`

	// Time after which an idle connection will be closed
	PoolMaxConnIdle time.Duration `json:"poolMaxConnIdle" mapstructure:"poolMaxConnIdle"`

	// Checks each connection taken from the pool to ensure it's alive
	// Otherwise, pgx will drop it and provide a new one
	// Disabling this check speeds up queries,
	// but if a bad connection is encountered, the query will fail with an error
	EnableBeforeAcquirePing bool `json:"enableBeforeAcquirePing" mapstructure:"enableBeforeAcquirePing"`

	// Allows the scanner to ignore database columns that do not exist in the destination
	AllowUnknownColumns bool `json:"allowUnknownColumns" mapstructure:"allowUnknownColumns"`
}

func (*Config) Valid

func (c *Config) Valid() error

Jump to

Keyboard shortcuts

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