postgres

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2020 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

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 represents a client for PostgreSQL.

func NewClient

func NewClient(options ...ConfigOption) *Client

NewClient returns a new Postgres client to manage repositories.

func TestClient

func TestClient(db *sql.DB) *Client

TestClient returns a test client with necessary dependencies already provided.

func (*Client) Device

func (c *Client) Device() auth.DeviceRepository

Device returns a DeviceRepository.

func (*Client) LoginHistory

func (c *Client) LoginHistory() auth.LoginHistoryRepository

LoginHistory returns a LoginRepository.

func (*Client) NewWithTransaction

func (c *Client) NewWithTransaction(ctx context.Context) (auth.RepositoryManager, error)

NewWithTransaction returns a new client with a transaction. All repository operations using the new client will default to the transaction.

func (*Client) User

func (c *Client) User() auth.UserRepository

User returns a UserRepository.

func (*Client) WithAtomic

func (c *Client) WithAtomic(operation func() (interface{}, error)) (interface{}, error)

WithAtomic performs an operation within a transaction. If the operation is successful it commits it, otherwise the operation will be rolledback.

type ConfigOption

type ConfigOption func(*Client)

ConfigOption configures the Client.

func WithDB

func WithDB(db *sql.DB) ConfigOption

WithDB configures the client with a Postgres DB.

func WithLogger

func WithLogger(l log.Logger) ConfigOption

WithLogger configures the client with a Logger.

func WithPassword

func WithPassword(p auth.PasswordService) ConfigOption

WithPassword configures the client with a PasswordService.

type DeviceRepository

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

DeviceRepository is an implementation of auth.DeviceRepository interface.

func (*DeviceRepository) ByClientID

func (r *DeviceRepository) ByClientID(ctx context.Context, userID string, clientID []byte) (*auth.Device, error)

ByClientID retrieves a Device with a matching ClientID.

func (*DeviceRepository) ByID

func (r *DeviceRepository) ByID(ctx context.Context, deviceID string) (*auth.Device, error)

ByID retrieves a Device with a matching ID.

func (*DeviceRepository) ByUserID

func (r *DeviceRepository) ByUserID(ctx context.Context, userID string) ([]*auth.Device, error)

ByUserID retrieves all Devices associated with a User.

func (*DeviceRepository) Create

func (r *DeviceRepository) Create(ctx context.Context, device *auth.Device) error

Create persists a new Device to a storage.

func (*DeviceRepository) GetForUpdate

func (r *DeviceRepository) GetForUpdate(ctx context.Context, deviceID string) (*auth.Device, error)

GetForUpdate retrieves a Device to be updated.

func (*DeviceRepository) Remove

func (r *DeviceRepository) Remove(ctx context.Context, deviceID, userID string) error

Remove removes a Device associated with a User.

func (*DeviceRepository) Update

func (r *DeviceRepository) Update(ctx context.Context, device *auth.Device) error

Update updates a Device in storage.

type LoginHistoryRepository

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

LoginHistoryRepository is an implementation of auth.LoginHistoryRepository.

func (*LoginHistoryRepository) ByTokenID

func (r *LoginHistoryRepository) ByTokenID(ctx context.Context, tokenID string) (*auth.LoginHistory, error)

ByTokenID retrieves a LoginHistory record with matching JWT token ID.

func (*LoginHistoryRepository) ByUserID

func (r *LoginHistoryRepository) ByUserID(ctx context.Context, userID string, limit, offset int) ([]*auth.LoginHistory, error)

ByUserID retrieves all LoginHistory records associated with a User.

func (*LoginHistoryRepository) Create

Create persists a new LoginHistory to storage.

func (*LoginHistoryRepository) GetForUpdate

func (r *LoginHistoryRepository) GetForUpdate(ctx context.Context, tokenID string) (*auth.LoginHistory, error)

GetForUpdate retrieves a LoginHistory to be updated.

func (*LoginHistoryRepository) Update

Update updates a LoginHistory in storage.

type UserRepository

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

UserRepository is an implementation of auth.UserRepository.

func (*UserRepository) ByIdentity

func (r *UserRepository) ByIdentity(ctx context.Context, attribute, value string) (*auth.User, error)

ByIdentity retrieves a User by their phone, email, or unique ID.

func (*UserRepository) Create

func (r *UserRepository) Create(ctx context.Context, user *auth.User) error

Create persists a new User to local storage.

func (*UserRepository) DisableOTP

func (r *UserRepository) DisableOTP(ctx context.Context, userID string, method auth.DeliveryMethod) (*auth.User, error)

DisableOTP disables an OTP delivery method for a User.

func (*UserRepository) GetForUpdate

func (r *UserRepository) GetForUpdate(ctx context.Context, userID string) (*auth.User, error)

GetForUpdate retrieves a User to be updated.

func (*UserRepository) ReCreate

func (r *UserRepository) ReCreate(ctx context.Context, user *auth.User) error

ReCreate updates an existing unverified User record with new a new creation timestamp and primary key value to treat the user as a newly created record. New Users remain in an unverified state until completing OTP verification to prove ownership of a phone or email address.

func (*UserRepository) RemoveDeliveryMethod

func (r *UserRepository) RemoveDeliveryMethod(ctx context.Context, userID string, method auth.DeliveryMethod) (*auth.User, error)

RemoveDeliveryMethod removes a phone or email from a User.

func (*UserRepository) Update

func (r *UserRepository) Update(ctx context.Context, user *auth.User) error

Update updates a User in storage.

Jump to

Keyboard shortcuts

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