pg

package
v0.0.0-...-800adf3 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2022 License: ISC Imports: 13 Imported by: 4

Documentation

Index

Constants

View Source
const AdvisoryLockId1 uint32 = 0x00ff

Advisory locks are identified by two 32 bit integers. We arbitrarily reserve a value for the first one for all locks taken by go-daemon.

View Source
const (
	AdvisoryLockId2Migrations uint32 = 0x0001
)
View Source
const MigrationVersionLayout = "20060102T150405Z"

Variables

This section is empty.

Functions

func Exec

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

func Exec2

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

func Exec2Context

func Exec2Context(ctx context.Context, conn Conn, query string, args ...interface{}) (int64, error)

func ExecContext

func ExecContext(ctx context.Context, conn Conn, query string, args ...interface{}) error

func QueryObject

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

func QueryObjectContext

func QueryObjectContext(ctx context.Context, conn Conn, obj Object, query string, args ...interface{}) error

func QueryObjects

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

func QueryObjectsContext

func QueryObjectsContext(ctx context.Context, conn Conn, objs Objects, query string, args ...interface{}) error

func QuoteIdentifier

func QuoteIdentifier(s string) string

func QuoteString

func QuoteString(s string) string

func TakeAdvisoryLock

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

func ValidateMigrationVersion

func ValidateMigrationVersion(s string) (err error)

Types

type Client

type Client struct {
	Cfg ClientCfg
	Log *dlog.Logger

	Pool *pgxpool.Pool
}

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) (err error)

type ClientCfg

type ClientCfg struct {
	Log *dlog.Logger `json:"-"`

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

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

func (*ClientCfg) Check

func (cfg *ClientCfg) Check(c *check.Checker)

type Conn

type Conn interface {
	Begin(context.Context) (pgx.Tx, error)
	BeginFunc(context.Context, func(pgx.Tx) error) error
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
	QueryFunc(context.Context, string, []interface{}, []interface{}, func(pgx.QueryFuncRow) error) (pgconn.CommandTag, error)
}

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