pg

package
v1.0.27 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTxCommitRollback = pgx.ErrTxCommitRollback
	ErrTooManyRows      = pgx.ErrTooManyRows
	ErrTxClosed         = pgx.ErrTxClosed
	ErrNoRows           = pgx.ErrNoRows
)

Functions

This section is empty.

Types

type Batch added in v1.0.18

type Batch = pgx.Batch

type BatchResults added in v1.0.18

type BatchResults = pgx.BatchResults

type Client

type Client interface {
	Pool

	RegisterTypes(types []string) error

	ToPgx() *pgxpool.Pool
}

Client is interface for communicate with postgres database.

func New added in v1.0.15

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

ConnectToDb returns a pointer to a pgxpool.Pool representing the database connection pool.

func NewWithMock added in v1.0.21

func NewWithMock(pool Pool) Client

func NewWithPool added in v1.0.17

func NewWithPool(ctx context.Context, pool *pgxpool.Pool) (Client, error)

type Config

type Config struct {
	Host           string `yaml:"host"     env:"PG_HOST"    env-default:"localhost"`
	Port           int    `yaml:"port"     env:"PG_PORT"    env-default:"5432"`
	DBName         string `yaml:"dbname"   env:"PG_NAME"    env-default:"postgres"`
	Username       string `yaml:"username" env:"PG_USER"`
	Password       string `env:"POSTGRES_PASSWORD"`
	SSLMode        string `yaml:"sslmode"  env:"PG_SSLMODE" env-default:"disabled"`
	MigrationsRun  bool   `yaml:"migrations_run" env:"PG_MIGRATIONS_RUN" env-default:"false"`
	MigrationsPath string `yaml:"migrations_path" env:"PG_MIGRATIONS_PATH"`
}

Config is type for database connection.

type Conn added in v1.0.18

type Conn = pgx.Conn

type CopyFromSource added in v1.0.18

type CopyFromSource = pgx.CopyFromSource

type Identifier added in v1.0.18

type Identifier = pgx.Identifier

type Pool added in v1.0.18

type Pool interface {
	Acquire(ctx context.Context) (c *pgxpool.Conn, err error)
	AcquireFunc(ctx context.Context, f func(*pgxpool.Conn) error) error
	Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)
	AcquireAllIdle(ctx context.Context) []*pgxpool.Conn
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
	SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)
	CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)
	Ping(ctx context.Context) error
	Begin(ctx context.Context) (pgx.Tx, error)
	Stat() *pgxpool.Stat
	Config() *pgxpool.Config
	Reset()
	Close()
}

type Row

type Row = pgx.Row

type Rows added in v1.0.18

type Rows = pgx.Rows

type Stat added in v1.0.18

type Stat = pgxpool.Stat

type Tx added in v1.0.18

type Tx = pgx.Tx

type TxOptions added in v1.0.18

type TxOptions = pgx.TxOptions

Jump to

Keyboard shortcuts

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