store

package
v0.0.0-...-6343e97 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrInvalidEmail is returned when the email is not a valid address or is empty.
	ErrInvalidEmail = errors.Error("invalid_email: email is invalid")
	// ErrEmailAlreadyUsed is returned when the email address is already used via another user.
	ErrEmailAlreadyUsed = errors.Error("email_already_used: email is already in use")
	// ErrEmptyNickname is returned when the nickname is empty.
	ErrEmptyNickname = errors.Error("empty_nickname: nickname is empty")
	// ErrNicknameAlreadyUsed is returned when the nickname is already used via another user.
	ErrNicknameAlreadyUsed = errors.Error("nickname_already_used: nickname is already in use")
	// ErrEmptyPassword is returned when the password is empty.
	ErrEmptyPassword = errors.Error("empty_password: password is empty")
	// ErrEmptyCountry is returned when the country is empty.
	ErrEmptyCountry = errors.Error("empty_country: password is empty")
	// ErrInvalidID si returned when the ID is not a valid UUID or is empty.
	ErrInvalidID = errors.Error("invalid_id: id is invalid")
	// ErrUserNotUpdated is returned when a record can't be found to update.
	ErrUserNotUpdated = errors.Error("user_not_updated: user record wasn't updated")
	// ErrUserNotDeleted is returned when a record can't be found to delete.
	ErrUserNotDeleted = errors.Error("user_not_deleted: user record wasn't deleted")
	// ErrInvalidFilters is returned when the filters for finding a user are not valid.
	ErrInvalidFilters = errors.Error("invalid_filters: filters invalid for finding user")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB interface {
	NamedQueryContext(ctx context.Context, query string, arg interface{}) (*sqlx.Rows, error)
	GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)
}

DB represents a type for interfacing with a postgres database.

type Store

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

Store provides functionality for working with a postgres database.

func New

func New(db DB) *Store

New will instantiate a new instance of Store.

func (*Store) DeleteUser

func (s *Store) DeleteUser(ctx context.Context, id string) error

DeleteUser will delete an existing user via their ID.

func (*Store) FindUsers

func (s *Store) FindUsers(ctx context.Context, filters []model.Filter, offset, limit int64) ([]*model.User, error)

FindUsers will retrieve a list of users based on matching all of the the provided filters and using pagination if limit is gt 0 Note: depending on the actual use cases for such functionality I would probably take the route of using elasticsearch and opening up the flexibility of having a search type function.

func (*Store) GetUser

func (s *Store) GetUser(ctx context.Context, id string) (*model.User, error)

GetUser will retrieve an existing user via their ID.

func (*Store) GetUserByEmail

func (s *Store) GetUserByEmail(ctx context.Context, email string) (*model.User, error)

GetUserByEmail will retrieve an existing user via their email address.

func (*Store) InsertUser

func (s *Store) InsertUser(ctx context.Context, u *model.User) (*model.User, error)

InsertUser will add a new unique user to the database using the provided data.

func (*Store) UpdateUser

func (s *Store) UpdateUser(ctx context.Context, u *model.User) (*model.User, error)

UpdateUser will update an existing user in the database using only the present data provided.

Jump to

Keyboard shortcuts

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