repo

package
v0.0.0-...-1c92e5d Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserNotFound = errors.New("user could not be found")
)

Errors that can be returned from the repo.

Functions

This section is empty.

Types

type OrderBy

type OrderBy int

OrderBy is an enumeration over sort orders

const (
	OrderByName OrderBy = iota
	OrderByCreateTime
)

Cover all the supported sort orders

type Repository

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

Repository is used to store and fetch users from a database.

func NewRepository

func NewRepository(dbURL string, logger *logrus.Logger) (*Repository, error)

NewRepository creates a new, database-backed repository.

func (Repository) Close

func (r Repository) Close() error

Close releases the resources of the Repository.

func (Repository) CreateUser

func (r Repository) CreateUser(ctx context.Context, name string) (User, error)

CreateUser creates a new user in the repository.

func (Repository) GetUser

func (r Repository) GetUser(ctx context.Context, id string) (User, error)

GetUser retrieves any information held for a given user ID.

func (Repository) ListUsers

func (r Repository) ListUsers(ctx context.Context, names []string, order *SortOrder) (_ []User, err error)

ListUsers will return all users matching the filters.

type SortOrder

type SortOrder struct {
	By         OrderBy
	Descending bool
}

SortOrder describes how to sort results

func (*SortOrder) SQL

func (s *SortOrder) SQL() string

SQL returns the SQL representation of SortOrder, suitable for use in an OrderBy clause.

type User

type User struct {
	ID         string
	Name       string
	CreateTime time.Time
}

User describes the database model for a User.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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