psql

package
v0.0.0-...-6343e97 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrDriverInit is returned when we cannot initialize the driver.
	ErrDriverInit = errors.Error("failed to initialize postgres driver")
	// ErrMigrateInit is returned when we cannot initialize the migrate driver.
	ErrMigrateInit = errors.Error("failed to initialize migration driver")
	// ErrMigration is returned when we cannot run a migration.
	ErrMigration = errors.Error("failed to migrate database")
)
View Source
const (
	// ErrConnect is returned when we cannot connect to the database.
	ErrConnect = errors.Error("failed to connect to postgres db")
	// ErrClose is returned when we cannot close the database.
	ErrClose = errors.Error("failed to close postgres db connection")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	DSN string `env:"POSTGRES_DSN" validate:"required"`
}

Config represents the configuration for our postgres database.

type Driver

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

Driver provides an implementation for connecting to a postgres database.

func New

func New(cfg Config) *Driver

New instantiates a instance of the Driver.

func (*Driver) Close

func (d *Driver) Close(ctx context.Context) error

Close closes the database connection.

func (*Driver) Connect

func (d *Driver) Connect(ctx context.Context) error

Connect connects to the database.

func (*Driver) GetDB

func (d *Driver) GetDB() *sqlx.DB

GetDB returns the underlying database connection.

func (*Driver) MigratePostgres

func (d *Driver) MigratePostgres(ctx context.Context, migrationsPath string) error

MigratePostgres migrates the database to the latest version.

func (*Driver) RevertMigrations

func (d *Driver) RevertMigrations(ctx context.Context, migrationsPath string) error

RevertMigrations reverts the database to the previous version.

Jump to

Keyboard shortcuts

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