repositories

package
v0.0.0-...-e2f3688 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var All = [...]string{"DbUserRepo", "DbAnimalRepo", "DbAdoptionRepo", "DbAdopterRepo"}

All is a list of all the repository names

Functions

This section is empty.

Types

type DbAdopterRepo

type DbAdopterRepo DbRepo

DbAdopterRepo is the repository for adopters.

func NewDbAdopterRepo

func NewDbAdopterRepo(dbHandlers map[string]DbHandler) *DbAdopterRepo

NewDbAdopterRepo istanciates and returns a user repository.

func (*DbAdopterRepo) FindByID

func (db *DbAdopterRepo) FindByID(id int) (domain.Adopter, error)

FindByID retrieves a user by the specified id.

func (*DbAdopterRepo) Store

func (db *DbAdopterRepo) Store(adopter domain.Adopter) error

Store saves the new adopter into the repository

type DbAdoptionRepo

type DbAdoptionRepo DbRepo

DbAdoptionRepo is the repository for adoptions.

func NewDbAdoptionRepo

func NewDbAdoptionRepo(dbHandlers map[string]DbHandler) *DbAdoptionRepo

NewDbAdoptionRepo istanciates and returns a user repository.

func (*DbAdoptionRepo) FindAllByAdopterID

func (db *DbAdoptionRepo) FindAllByAdopterID(id int) ([]domain.Adoption, error)

FindAllByAdopterID returns a list of all the adoptions related to the specified user ID.

func (*DbAdoptionRepo) FindByID

func (db *DbAdoptionRepo) FindByID(id int) (domain.Adoption, error)

FindByID retrieves an adoptions given its ID

func (*DbAdoptionRepo) FindMaxID

func (db *DbAdoptionRepo) FindMaxID() (id int, err error)

FindMaxID retrieves the last inserted ID. This is a bad practice, we are using it here just to enable the project to run as a demo.

func (*DbAdoptionRepo) Store

func (db *DbAdoptionRepo) Store(adoption domain.Adoption) error

Store saves the new adoption into the repository.

type DbAnimalRepo

type DbAnimalRepo DbRepo

DbAnimalRepo is the repository for animals.

func NewDbAnimalRepo

func NewDbAnimalRepo(dbHandlers map[string]DbHandler) *DbAnimalRepo

NewDbAnimalRepo istanciates and returns a user repository.

func (*DbAnimalRepo) FindAllAdoptable

func (db *DbAnimalRepo) FindAllAdoptable() ([]domain.Animal, error)

FindAllAdoptable returns a list of all the animals in the repository.

func (*DbAnimalRepo) FindByID

func (db *DbAnimalRepo) FindByID(id int) (domain.Animal, error)

FindByID retrieves an animals given its ID.

func (*DbAnimalRepo) Store

func (db *DbAnimalRepo) Store(animal domain.Animal) error

Store saves the new animal into the repository. Every stored animal is available by deafult.

type DbHandler

type DbHandler interface {
	Execute(statement string) error
	Query(statement string) (Row, error)
}

DbHandler is a high level interface that allows repository interrogation by hiding all the low level aspects.

type DbRepo

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

DbRepo represents a general repository. The handlers map lets every repository use any other repository without giving up dependency injection.

type DbUserRepo

type DbUserRepo DbRepo

DbUserRepo is the repository for the users.

func NewDbUserRepo

func NewDbUserRepo(dbHandlers map[string]DbHandler) *DbUserRepo

NewDbUserRepo istanciates and returns a user repository.

func (*DbUserRepo) FindByID

func (db *DbUserRepo) FindByID(id int) (usecases.User, error)

FindByID retrieves a user given its ID.

func (*DbUserRepo) Store

func (db *DbUserRepo) Store(user usecases.User) error

Store saves the new user into the repository

type Row

type Row interface {
	Scan(dest ...interface{}) error
	Next() bool
	Close() error
}

Row is a high level interface that allows data manipulation.

Jump to

Keyboard shortcuts

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