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
- type Account
- type Factory
- type Storer
- func (s *Storer) Create(ctx context.Context, account accounts.Account) error
- func (s *Storer) Delete(ctx context.Context, id string) error
- func (s *Storer) Get(ctx context.Context, id string) (accounts.Account, error)
- func (s *Storer) ListByProfile(ctx context.Context, profileID string) ([]accounts.Account, error)
- func (s *Storer) Update(ctx context.Context, id string, change accounts.Change) error
Constants ¶
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 ¶
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
func NewFactory ¶
func (*Factory) TeardownStorers ¶
type Storer ¶
type Storer struct {
// contains filtered or unexported fields
}
Storer provides a PostgreSQL-backed implementation of the Storer interface.
func NewStorer ¶
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 ¶
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 ¶
Delete removes the Account that matches the passed ID from the PostgreSQL database, if any Account matches the passed ID.
func (*Storer) Get ¶
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 ¶
ListByProfile returns all the Accounts associated with the passed profile ID, sorted with the most recently used Accounts coming first.
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. |