postgres

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxConns = 16
	DefaultMinConns = 0
	DefaultLogLevel = tracelog.LogLevelError
)

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, conf Config) (*pgx.Conn, error)

New creates a new connection to the database

func NewPool

func NewPool(ctx context.Context, conf Config) (*pgxpool.Pool, error)

NewPool creates a new connection pool to the database

Types

type Config

type Config struct {
	Host     string `mapstructure:"host"`     // Default is 127.0.0.1
	Port     string `mapstructure:"port"`     // Default is 5432
	User     string `mapstructure:"user"`     // Default is empty
	Password string `mapstructure:"password"` // Default is empty
	DBName   string `mapstructure:"db_name"`  // Default is postgres
	SSLMode  string `mapstructure:"ssl_mode"` // Default is prefer
	URL      string `mapstructure:"url"`      // If URL is provided, other fields are ignored

	MaxConns int32 `mapstructure:"max_conns"` // Default is 16
	MinConns int32 `mapstructure:"min_conns"` // Default is 0

	Debug bool `mapstructure:"debug"`
}

func (Config) QueryTracer

func (conf Config) QueryTracer() pgx.QueryTracer

func (Config) String

func (conf Config) String() string

String returns the connection string (DSN format or URL format)

type DB

type DB interface {
	Queryable
	TxQueryable
	SendBatch(ctx context.Context, b *pgx.Batch) (br pgx.BatchResults)
	Ping(ctx context.Context) error
}

DB is an interface that can be used to execute queries and commands, and also to send batches

type Queryable

type Queryable interface {
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
}

Queryable is an interface that can be used to execute queries and commands

type TxQueryable

type TxQueryable interface {
	Queryable
	Begin(context.Context) (pgx.Tx, error)
	BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)
}

TxQueryable is an interface that can be used to execute queries and commands within a transaction

Jump to

Keyboard shortcuts

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