pg

package
v0.0.0-...-c393e39 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: ISC Imports: 16 Imported by: 4

Documentation

Index

Constants

View Source
const (
	DefaultPoolSize                     = 5
	DefaultConnectionAcquisitionTimeout = 5000 // milliseconds
)
View Source
const AdvisoryLockId1 uint32 = 0x0100
View Source
const (
	AdvisoryLockId2Migrations uint32 = 0x0001
)
View Source
const MigrationVersionLayout = "20060102T150405Z"

Variables

View Source
var (
	ErrNoConnectionAvailable = errors.New("no connection available")
)

Functions

func Exec

func Exec(conn Conn, query string, args ...interface{}) (err error)

func Exec2

func Exec2(conn Conn, query string, args ...interface{}) (int64, error)

func Query

func Query(conn Conn, query string, args ...interface{}) (pgx.Rows, error)

func QueryObject

func QueryObject(conn Conn, obj Object, query string, args ...interface{}) error

func QueryObjects

func QueryObjects(conn Conn, objs Objects, query string, args ...interface{}) error

func QueryRow

func QueryRow(conn Conn, query string, args ...interface{}) pgx.Row

func QuoteIdentifier

func QuoteIdentifier(s string) string

func QuoteString

func QuoteString(s string) string

func TakeAdvisoryTxLock

func TakeAdvisoryTxLock(conn Conn, id1, id2 uint32) error

func ValidateMigrationVersion

func ValidateMigrationVersion(s string) (err error)

Types

type Client

type Client struct {
	Cfg ClientCfg
	Log *log.Logger

	Pool *pgxpool.Pool
	// contains filtered or unexported fields
}

func NewClient

func NewClient(cfg ClientCfg) (*Client, error)

func (*Client) Close

func (c *Client) Close()

func (*Client) UpdateSchema

func (c *Client) UpdateSchema(schema, dirPath string) error

func (*Client) WithConn

func (c *Client) WithConn(fn func(Conn) error) error

func (*Client) WithTx

func (c *Client) WithTx(fn func(Conn) error) error

type ClientCfg

type ClientCfg struct {
	Log          *log.Logger    `json:"-"`
	InfluxClient *influx.Client `json:"-"`
	Name         string         `json:"-"`

	URI             string `json:"uri"`
	ApplicationName string `json:"application_name,omitempty"`

	PoolSize int `json:"pool_size,omitempty"`

	ConnectionAcquisitionTimeout int `json:"connection_acquisition_timeout,omitempty"` // milliseconds

	SchemaDirectory string   `json:"schema_directory"`
	SchemaNames     []string `json:"schema_names"`
}

func (*ClientCfg) ValidateJSON

func (cfg *ClientCfg) ValidateJSON(v *ejson.Validator)

type Conn

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

type Migration

type Migration struct {
	Schema  string
	Version string
	Code    []byte
}

func (*Migration) Apply

func (m *Migration) Apply(conn Conn) error

func (*Migration) LoadFile

func (m *Migration) LoadFile(filePath string) error

func (*Migration) String

func (m *Migration) String() string

type Migrations

type Migrations []*Migration

func (*Migrations) LoadDirectory

func (pms *Migrations) LoadDirectory(schema, dirPath string) error

func (*Migrations) RejectVersions

func (pms *Migrations) RejectVersions(versions map[string]struct{})

func (Migrations) Sort

func (ms Migrations) Sort()

type Object

type Object interface {
	FromRow(pgx.Row) error
}

type Objects

type Objects interface {
	AddFromRow(pgx.Row) error
}

Jump to

Keyboard shortcuts

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