pg

package module
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2025 License: MIT Imports: 14 Imported by: 0

README

Pg

Pg is a PostgreSQL client designed to simplify things like configuration, mapping of model fields, etc.

It uses pgx to connect to PostgreSQL.

Installation

go get github.com/gosuit/pg/v2

Features

  • Easy client configuration
  • Model's fields mapping
  • Concise transaction management

Documentation

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue for any enhancements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Documentation

Index

Constants

View Source
const (
	Serializable    TxIsoLevel = pgx.Serializable
	RepeatableRead  TxIsoLevel = pgx.RepeatableRead
	ReadCommitted   TxIsoLevel = pgx.ReadCommitted
	ReadUncommitted TxIsoLevel = pgx.ReadUncommitted

	ReadWrite TxAccessMode = pgx.ReadWrite
	ReadOnly  TxAccessMode = pgx.ReadOnly

	Deferrable    TxDeferrableMode = pgx.Deferrable
	NotDeferrable TxDeferrableMode = pgx.NotDeferrable
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Argument

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

func Arg

func Arg(key string, value any) *Argument

type Client

type Client interface {
	Query(sql string, dest any) Query
	Command(sql string, src any) Command
	Transactional(ctx context.Context, fn TxFunc, opts ...TxOption) error

	ToPgx() *pgxpool.Pool
	ToDB() *sql.DB
	Close()
}

func New

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

type Command

type Command interface {
	WithArgs(args ...*Argument) Command
	WithArg(key string, value any) Command
	Returning(dest any) Command
	Exec(ctx context.Context) error
}

type Config

type Config struct {
	Host     string `confy:"host"     yaml:"host"     json:"host"     toml:"host"     env:"PG_HOST"    default:"localhost"`
	Port     int    `confy:"port"     yaml:"port"     json:"port"     toml:"port"     env:"PG_PORT"    default:"5432"`
	DBName   string `confy:"dbname"   yaml:"dbname"   json:"dbname"   toml:"dbname"   env:"PG_NAME"    default:"postgres"`
	Username string `confy:"username" yaml:"username" json:"username" toml:"username" env:"PG_USER"`
	Password string `confy:"password" env:"POSTGRES_PASSWORD"`
	SSLMode  string `confy:"sslmode"  yaml:"sslmode" json:"sslmode"  toml:"sslmode"   env:"PG_SSLMODE" default:"disable"`
}

type Query

type Query interface {
	WithArgs(args ...*Argument) Query
	WithArg(key string, value any) Query
	Exec(ctx context.Context) error
}

type TxAccessMode

type TxAccessMode = pgx.TxAccessMode

type TxDeferrableMode

type TxDeferrableMode = pgx.TxDeferrableMode

type TxFunc

type TxFunc func(ctx context.Context) error

type TxIsoLevel

type TxIsoLevel = pgx.TxIsoLevel

type TxOption

type TxOption func(opts *pgx.TxOptions)

func WithAccess

func WithAccess(access TxAccessMode) TxOption

func WithBeginQuery

func WithBeginQuery(query string) TxOption

func WithCommitQuery

func WithCommitQuery(query string) TxOption

func WithDeferrable

func WithDeferrable(deferrable TxDeferrableMode) TxOption

func WithLevel

func WithLevel(level TxIsoLevel) TxOption

Directories

Path Synopsis
docs
command command
init command
query command
transaction command

Jump to

Keyboard shortcuts

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