postgres

package
v0.6.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: 18 Imported by: 1

Documentation

Overview

Package postgres provides an implementation of the lockbox.dev/clients.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 Client

type Client struct {
	ID           string    `sql_column:"id"`
	Name         string    `sql_column:"name"`
	SecretHash   string    `sql_column:"secret_hash"`
	SecretScheme string    `sql_column:"secret_scheme"`
	Confidential bool      `sql_column:"confidential"`
	CreatedAt    time.Time `sql_column:"created_at"`
	CreatedBy    string    `sql_column:"created_by"`
	CreatedByIP  string    `sql_column:"created_by_ip"`
}

func (Client) GetSQLTableName

func (p Client) 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) (clients.Storer, error)

func (*Factory) TeardownStorers

func (p *Factory) TeardownStorers() error

type RedirectURI

type RedirectURI struct {
	ID          string    `sql_column:"id"`
	URI         string    `sql_column:"uri"`
	IsBaseURI   bool      `sql_column:"is_base_uri"`
	ClientID    string    `sql_column:"client_id"`
	CreatedAt   time.Time `sql_column:"created_at"`
	CreatedBy   string    `sql_column:"created_by"`
	CreatedByIP string    `sql_column:"created_by_ip"`
}

func (RedirectURI) GetSQLTableName

func (p RedirectURI) GetSQLTableName() string

type Storer

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

Postgres is an implementation of the Storer interface that stores data in a PostgreSQL database.

func NewStorer

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

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

func (Storer) AddRedirectURIs

func (s Storer) AddRedirectURIs(ctx context.Context, uris []clients.RedirectURI) error

func (Storer) Create

func (s Storer) Create(ctx context.Context, client clients.Client) error

func (Storer) Delete

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

func (Storer) Get

func (s Storer) Get(ctx context.Context, id string) (clients.Client, error)

func (Storer) ListRedirectURIs

func (s Storer) ListRedirectURIs(ctx context.Context, clientID string) ([]clients.RedirectURI, error)

func (Storer) RemoveRedirectURIs

func (s Storer) RemoveRedirectURIs(ctx context.Context, uris []string) error

func (Storer) Update

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

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