postgres

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnTimeout = errors.New("connection timeout")
	ErrNoRows      = errors.New("no rows")
)
View Source
var ErrUnsupportedCopyDataMessage = errors.New("unsupported copy data message")

Functions

func DefaultReplicationSlotName added in v0.3.0

func DefaultReplicationSlotName(dbName string) string

func RunPGDump added in v0.4.0

func RunPGDump(opts PGDumpOptions) ([]byte, error)

Func RunPGDump runs pg_dump command with the given options and returns the result.

func RunPGRestore added in v0.4.0

func RunPGRestore(opts PGRestoreOptions, dump []byte) (string, error)

Func RunPGRestore runs pg_restore command with the given options and returns the result.

Types

type CommandTag

type CommandTag struct {
	pgconn.CommandTag
}

type Conn

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

func NewConn

func NewConn(ctx context.Context, url string) (*Conn, error)

func (*Conn) Close

func (c *Conn) Close(ctx context.Context) error

func (*Conn) Exec

func (c *Conn) Exec(ctx context.Context, query string, args ...any) (CommandTag, error)

func (*Conn) ExecInTx added in v0.3.0

func (c *Conn) ExecInTx(ctx context.Context, fn func(Tx) error) error

func (*Conn) ExecInTxWithOptions added in v0.3.0

func (c *Conn) ExecInTxWithOptions(ctx context.Context, fn func(Tx) error, opts TxOptions) error

func (*Conn) Query

func (c *Conn) Query(ctx context.Context, query string, args ...any) (Rows, error)

func (*Conn) QueryRow

func (c *Conn) QueryRow(ctx context.Context, query string, args ...any) Row

type ErrConstraintViolation added in v0.4.0

type ErrConstraintViolation struct {
	Details string
}

func (*ErrConstraintViolation) Error added in v0.4.0

func (e *ErrConstraintViolation) Error() string

type ErrDataException added in v0.4.1

type ErrDataException struct {
	Details string
}

func (*ErrDataException) Error added in v0.4.1

func (e *ErrDataException) Error() string

type ErrRelationDoesNotExist added in v0.4.0

type ErrRelationDoesNotExist struct {
	Details string
}

func (*ErrRelationDoesNotExist) Error added in v0.4.0

func (e *ErrRelationDoesNotExist) Error() string

type ErrSyntaxError added in v0.4.0

type ErrSyntaxError struct {
	Details string
}

func (*ErrSyntaxError) Error added in v0.4.0

func (e *ErrSyntaxError) Error() string

type Error

type Error struct {
	Severity string
	Msg      string
}

func (*Error) Error

func (e *Error) Error() string

type IdentifySystemResult

type IdentifySystemResult pglogrepl.IdentifySystemResult

type Mapper added in v0.3.0

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

func NewMapper added in v0.3.0

func NewMapper() *Mapper

func (*Mapper) TypeForOID added in v0.3.0

func (m *Mapper) TypeForOID(oid uint32) string

type PGDumpOptions added in v0.4.0

type PGDumpOptions struct {
	// ConnectionString
	ConnectionString string
	// Format (c custom, d directory, t tar, p plain text)
	Format string
	// Schemas to export
	Schemas []string
	// Tables to export
	Tables []string
	// Tables to be excluded from the dump, regex patterns supported
	ExcludeTables []string
	// SchemaOnly if true, only schema will be exported (no data)
	SchemaOnly bool
	// do not dump privileges (grant/revoke)
	NoPrivileges bool
	// Options to pass to pg_dump
	Options []string
}

func (*PGDumpOptions) ToArgs added in v0.4.0

func (opts *PGDumpOptions) ToArgs() []string

type PGRestoreOptions added in v0.4.0

type PGRestoreOptions struct {
	// ConnectionString
	ConnectionString string
	// SchemaOnly if true, only schema will be restored (no data)
	SchemaOnly bool
	// Clean all the objects that will be restored
	Clean bool
	// Options to pass to pg_restore
	Options []string
}

func (PGRestoreOptions) ToArgs added in v0.4.0

func (opts PGRestoreOptions) ToArgs() []string

type Pool

type Pool struct {
	*pgxpool.Pool
}

func NewConnPool

func NewConnPool(ctx context.Context, url string) (*Pool, error)

func (*Pool) Close

func (c *Pool) Close(_ context.Context) error

func (*Pool) Exec

func (c *Pool) Exec(ctx context.Context, query string, args ...any) (CommandTag, error)

func (*Pool) ExecInTx added in v0.3.0

func (c *Pool) ExecInTx(ctx context.Context, fn func(Tx) error) error

func (*Pool) ExecInTxWithOptions added in v0.3.0

func (c *Pool) ExecInTxWithOptions(ctx context.Context, fn func(Tx) error, opts TxOptions) error

func (*Pool) Query

func (c *Pool) Query(ctx context.Context, query string, args ...any) (Rows, error)

func (*Pool) QueryRow

func (c *Pool) QueryRow(ctx context.Context, query string, args ...any) Row

type Querier

type Querier interface {
	Query(ctx context.Context, query string, args ...any) (Rows, error)
	QueryRow(ctx context.Context, query string, args ...any) Row
	Exec(ctx context.Context, query string, args ...any) (CommandTag, error)
	ExecInTx(ctx context.Context, fn func(tx Tx) error) error
	ExecInTxWithOptions(ctx context.Context, fn func(tx Tx) error, txOpts TxOptions) error
	Close(ctx context.Context) error
}

func ConnBuilder added in v0.4.1

func ConnBuilder(ctx context.Context, url string) (Querier, error)

func ConnPoolBuilder added in v0.4.1

func ConnPoolBuilder(ctx context.Context, url string) (Querier, error)

type QuerierBuilder added in v0.4.1

type QuerierBuilder func(context.Context, string) (Querier, error)

type ReplicationConfig

type ReplicationConfig struct {
	SlotName        string
	StartPos        uint64
	PluginArguments []string
}

type ReplicationConn

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

func NewReplicationConn

func NewReplicationConn(ctx context.Context, url string) (*ReplicationConn, error)

func (*ReplicationConn) Close

func (c *ReplicationConn) Close(ctx context.Context) error

func (*ReplicationConn) IdentifySystem

func (c *ReplicationConn) IdentifySystem(ctx context.Context) (IdentifySystemResult, error)

func (*ReplicationConn) ReceiveMessage

func (c *ReplicationConn) ReceiveMessage(ctx context.Context) (*ReplicationMessage, error)

func (*ReplicationConn) SendStandbyStatusUpdate

func (c *ReplicationConn) SendStandbyStatusUpdate(ctx context.Context, lsn uint64) error

func (*ReplicationConn) StartReplication

func (c *ReplicationConn) StartReplication(ctx context.Context, cfg ReplicationConfig) error

type ReplicationMessage

type ReplicationMessage struct {
	LSN            uint64
	ServerTime     time.Time
	WALData        []byte
	ReplyRequested bool
}

type Row

type Row interface {
	pgx.Row
}

type Rows

type Rows interface {
	pgx.Rows
}

type Tx added in v0.3.0

type Tx interface {
	Query(ctx context.Context, query string, args ...any) (Rows, error)
	QueryRow(ctx context.Context, query string, args ...any) Row
	Exec(ctx context.Context, query string, args ...any) (CommandTag, error)
}

type TxAccessMode added in v0.3.0

type TxAccessMode string
const (
	ReadWrite TxAccessMode = "read write"
	ReadOnly  TxAccessMode = "read only"
)

type TxIsolationLevel added in v0.3.0

type TxIsolationLevel string
const (
	Serializable    TxIsolationLevel = "serializable"
	RepeatableRead  TxIsolationLevel = "repeatable read"
	ReadCommitted   TxIsolationLevel = "read committed"
	ReadUncommitted TxIsolationLevel = "read uncommitted"
)

type TxOptions added in v0.3.0

type TxOptions struct {
	IsolationLevel TxIsolationLevel
	AccessMode     TxAccessMode
}

type Txn added in v0.3.0

type Txn struct {
	pgx.Tx
}

func (*Txn) Exec added in v0.3.0

func (t *Txn) Exec(ctx context.Context, query string, args ...any) (CommandTag, error)

func (*Txn) Query added in v0.3.0

func (t *Txn) Query(ctx context.Context, query string, args ...any) (Rows, error)

func (*Txn) QueryRow added in v0.3.0

func (t *Txn) QueryRow(ctx context.Context, query string, args ...any) Row

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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