pgx

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package pgx implements the Driver interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Conn

func Conn(c *pgx.Conn) driver.CopyConn

Conn wraps a postgresql connection and returns a driver.Conn

func MigrateSchemas added in v1.4.0

func MigrateSchemas(ctx context.Context, migrators ...MigratableDatabase) error

MigrateSchemas migrates all the passed in migratable databases

func New

func New(tableName string) driver.DumpDriver

New creates a new postgresql driver

func WithTransaction

func WithTransaction(ctx context.Context, tx driver.Tx, fn func() error) (err error)

WithTransaction wraps a transaction and handles rollback and commit and recovers if there are any panics

Types

type MigratableDatabase

type MigratableDatabase interface {
	GetPool() *pgxpool.Pool
	Schema() string
	Path() string
	Migrate(ctx context.Context) (schema string, fromVersion, toVersion file.Version, err error)
	Dump(context.Context, file.DumpWriter) error
	Restore(context.Context, file.DumpReader) error
	Revert(ctx context.Context) error
}

MigratableDatabase interface

type Row

type Row struct {
	pgx.Row
}

Row wraps *pgx.Row which is a convenience wrapper over *pgx.Rows

func (Row) Columns

func (r Row) Columns() ([]string, error)

Columns returns the column names for the row.

func (Row) Scan

func (r Row) Scan(dest ...interface{}) (err error)

Scan scans the data in the row into the provided input parameters.

type Rows

type Rows struct {
	pgx.Rows
}

Rows defines Columns so that sqlstruct.Scan can be used

func (Rows) Columns

func (r Rows) Columns() ([]string, error)

Columns returns the column names for the rows.

type SchemaMigrator

type SchemaMigrator struct {
	*pgxpool.Pool
	BaseMigrator migrate.Migrator
}

SchemaMigrator struct

func (*SchemaMigrator) Drop

func (m *SchemaMigrator) Drop(ctx context.Context) error

Drop rotates the schema to _bak and creates a new schema

func (*SchemaMigrator) Dump

func (m *SchemaMigrator) Dump(ctx context.Context, dw file.DumpWriter) (err error)

Dump write the database to the DumpWriter

func (*SchemaMigrator) FinishRestore

func (m *SchemaMigrator) FinishRestore(ctx context.Context, migrator migrate.Migrator, schemas []string) error

FinishRestore finishes the restore by rotating the schemas

func (*SchemaMigrator) GetPool added in v1.5.1

func (m *SchemaMigrator) GetPool() *pgxpool.Pool

Pool returns connection pool

func (*SchemaMigrator) InitCopy

func (m *SchemaMigrator) InitCopy(ctx context.Context, schemaSuffix string, d driver.DumpDriver, newPool func(string) *pgxpool.Pool, ensureSchema bool) SchemaMigrator

InitCopy makes a copy and initializes it

func (*SchemaMigrator) Migrate

func (m *SchemaMigrator) Migrate(ctx context.Context) (schema string, fromVersion, toVersion file.Version, err error)

Migrate migrate between schema versions

func (*SchemaMigrator) Path

func (m *SchemaMigrator) Path() string

Path returns the base path

func (*SchemaMigrator) Restore

func (m *SchemaMigrator) Restore(ctx context.Context, dr file.DumpReader) error

Restore restores the database from the passed in DumpReader

func (*SchemaMigrator) Revert

func (m *SchemaMigrator) Revert(ctx context.Context) error

Revert reverts the database to the previous version

func (*SchemaMigrator) Schema

func (m *SchemaMigrator) Schema() string

Schema returns the base schema

func (*SchemaMigrator) StartRestore

func (m *SchemaMigrator) StartRestore() (migrator migrate.Migrator, schemas []string)

StartRestore creates a migrator and schemas used during restore

func (*SchemaMigrator) StartRevert

func (m *SchemaMigrator) StartRevert() (migrator migrate.Migrator, schemas []string)

StartRevert creates a migrator and schemas used during revert

Jump to

Keyboard shortcuts

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