postgres

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2022 License: MIT Imports: 15 Imported by: 1

Documentation

Overview

Package postgres provides an implementation of the lockbox.dev/accounts.Storer interface that stores data in a PostgreSQL database.

The package assumes that the database is set up and ready for its use, and does not automatically set up the database itself. Migrations to set the database up are available in the sql folder of this package. The migrations are also available in the migrations package, which contains the contents of the sql folder packaged using go-bindata to make them easy to include in Go binaries. Migrations should be applied in lexicographical order, with numbers coming before letters.

Index

Constants

View Source
const (
	TestConnStringEnvVar = "PG_TEST_DB"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID             string       `sql_column:"id"`
	ProfileID      string       `sql_column:"profile_id"`
	Created        time.Time    `sql_column:"created_at"`
	LastUsed       time.Time    `sql_column:"last_used_at"`
	LastSeen       time.Time    `sql_column:"last_seen_at"`
	IsRegistration sql.NullBool `sql_column:"is_registration"`
}

func (Account) GetSQLTableName

func (p Account) GetSQLTableName() string

type Factory

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

func NewFactory

func NewFactory(db *sql.DB) *Factory

func (*Factory) NewStorer

func (p *Factory) NewStorer(ctx context.Context) (accounts.Storer, error)

func (*Factory) TeardownStorers

func (p *Factory) TeardownStorers() error

type Storer

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

Storer provides a PostgreSQL-backed implementation of the Storer interface.

func NewStorer

func NewStorer(ctx context.Context, conn *sql.DB) *Storer

NewStorer returns a Storer instance that is backed by the specified *sql.DB. The returned Storer instance is ready to be used as a Storer.

func (*Storer) Create

func (s *Storer) Create(ctx context.Context, account accounts.Account) error

Create inserts the passed Account into the PostgreSQL database, returning an ErrAccountAlreadyExists error if the Account's ID already exists in the database.

func (*Storer) Delete

func (s *Storer) Delete(ctx context.Context, id string) error

Delete removes the Account that matches the passed ID from the PostgreSQL database, if any Account matches the passed ID.

func (*Storer) Get

func (s *Storer) Get(ctx context.Context, id string) (accounts.Account, error)

Get retrieves the Account specified by the passed ID from the PostgreSQL database. If no Account matches the passed ID, an ErrAccountNotFound error is returned.

func (*Storer) ListByProfile

func (s *Storer) ListByProfile(ctx context.Context, profileID string) ([]accounts.Account, error)

ListByProfile returns all the Accounts associated with the passed profile ID, sorted with the most recently used Accounts coming first.

func (*Storer) Update

func (s *Storer) Update(ctx context.Context, id string, change accounts.Change) error

Update applies the passed Change to the Account in the PostgreSQL database that matches the specified ID, if any Account matches the specified ID.

Directories

Path Synopsis
Package migrations provides access to the SQL migrations used to set up a PostgreSQL database for the postgres Storer implementation.
Package migrations provides access to the SQL migrations used to set up a PostgreSQL database for the postgres Storer implementation.

Jump to

Keyboard shortcuts

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