db

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2022 License: Unlicense Imports: 5 Imported by: 0

Documentation

Overview

Package db implements a Postgres client for applying, querying, and recording migrations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a migration database connection.

func ClientFromPool

func ClientFromPool(ctx context.Context, pool *pgxpool.Pool) (*Client, error)

func Connect

func Connect(ctx context.Context, uri string) (*Client, error)

Connect connects to the Postgres database at the given uri.

func (*Client) Close

func (c *Client) Close() error

Close closes the underlying database connection.

func (*Client) Exec

func (c *Client) Exec(ctx context.Context, sql string) error

Exec executes the given statements against the database, and then records that the migration has been applied.

func (*Client) GetMigrations

func (c *Client) GetMigrations(ctx context.Context) ([]Migration, error)

GetMigrations returns all migrations that have been applied to the database.

func (*Client) LogCompletedMigration

func (c *Client) LogCompletedMigration(ctx context.Context, name string) error

LogCompletedMigration saves migration into the migration table.

func (*Client) TryLock

func (c *Client) TryLock(ctx context.Context) (bool, error)

TryLock attempts to acquire an exclusive lock for running migrations on this database.

func (*Client) Unlock

func (c *Client) Unlock(ctx context.Context) (bool, error)

Unlock unlocks the exclusive migration lock. If the provided context is cancelled this might leave the lock behind.

type Migration

type Migration struct {
	Name string
}

Migration is a migration that's been applied to the database.

Jump to

Keyboard shortcuts

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