dao

package
v0.0.0-...-3a230e9 Latest Latest
Warning

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

Go to latest
Published: May 13, 2018 License: Apache-2.0 Imports: 6 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// NoPaging used with skip, limit parameters
	NoPaging = -1
)

Variables

View Source
var (
	// ErrInvalidObjectID is used on invalid ObjectId
	ErrInvalidObjectID = errors.New("invalid input to ObjectIdHex")
)
View Source
var (
	// ErrorDAONotFound is used for unknown DAO type
	ErrorDAONotFound = errors.New("Unknown DAO type")
)
View Source
var MockedSpirit = model.Spirit{
	Name:         "Caroni",
	Distiller:    "Caroni",
	Bottler:      "Velier",
	Country:      "Trinidad",
	Composition:  "Molasse",
	SpiritType:   model.TypeRhum,
	Age:          15,
	BottlingDate: time.Date(2015, 01, 01, 0, 0, 0, 0, time.UTC),
	Score:        8.5,
	Comment:      "heavy tire taste",
}

MockedSpirit is the spirit returned by this mocked interface

Functions

This section is empty.

Types

type DBType

type DBType int

DBType define the type of DAO to be used

const (
	// DAOMongo is used for Mongo implementation of SpiritDAO
	DAOMongo DBType = iota
	// DAOMock is used for mocked implementation of SpiritDAO
	DAOMock
)

type SpiritDAO

type SpiritDAO interface {

	// GetSpiritByID returns a spirit by its ID
	GetSpiritByID(ID string) (*model.Spirit, error)

	// GetAllSpirits returns all spirits with paging capability
	GetAllSpirits(start, end int) ([]model.Spirit, error)

	// GetSpiritsByName returns all spirits by name
	GetSpiritsByName(name string) ([]model.Spirit, error)

	// GetSpiritsByType returns all spirits by type
	GetSpiritsByType(spiritType string) ([]model.Spirit, error)

	// GetSpiritsByTypeAndScore returns all spirits by type and score greater than parameter
	GetSpiritsByTypeAndScore(spiritType string, score uint8) ([]model.Spirit, error)

	// SaveSpirit saves the spirit
	SaveSpirit(spirit *model.Spirit) error

	// UpsertSpirit updates or creates a spirit
	UpsertSpirit(ID string, spirit *model.Spirit) (bool, error)

	// DeleteSpirit deletes a spirits by its ID
	DeleteSpirit(ID string) error
}

SpiritDAO is the DAO interface to work with spirits

func GetSpiritDAO

func GetSpiritDAO(param string, daoType DBType) (SpiritDAO, error)

GetSpiritDAO returns a SpiritDAO according to type and params

func NewSpiritDAOMock

func NewSpiritDAOMock() SpiritDAO

NewSpiritDAOMock creates a new SpiritDAO with a mocked implementation

func NewSpiritDAOMongo

func NewSpiritDAOMongo(session *mgo.Session) SpiritDAO

NewSpiritDAOMongo creates a new SpiritDAO mongo implementation

type SpiritDAOMock

type SpiritDAOMock struct {
}

SpiritDAOMock is the mocked implementation of the SpiritDAO

func (*SpiritDAOMock) DeleteSpirit

func (s *SpiritDAOMock) DeleteSpirit(ID string) error

DeleteSpirit deletes a spirits by its ID

func (*SpiritDAOMock) GetAllSpirits

func (s *SpiritDAOMock) GetAllSpirits(start, end int) ([]model.Spirit, error)

GetAllSpirits returns all spirits with paging capability

func (*SpiritDAOMock) GetSpiritByID

func (s *SpiritDAOMock) GetSpiritByID(ID string) (*model.Spirit, error)

GetSpiritByID returns a spirit by its ID

func (*SpiritDAOMock) GetSpiritsByName

func (s *SpiritDAOMock) GetSpiritsByName(name string) ([]model.Spirit, error)

GetSpiritsByName returns all spirits by name

func (*SpiritDAOMock) GetSpiritsByType

func (s *SpiritDAOMock) GetSpiritsByType(spiritType string) ([]model.Spirit, error)

GetSpiritsByType returns all spirits by type

func (*SpiritDAOMock) GetSpiritsByTypeAndScore

func (s *SpiritDAOMock) GetSpiritsByTypeAndScore(spiritType string, score uint8) ([]model.Spirit, error)

GetSpiritsByTypeAndScore returns all spirits by type and score greater than parameter

func (*SpiritDAOMock) SaveSpirit

func (s *SpiritDAOMock) SaveSpirit(spirit *model.Spirit) error

SaveSpirit saves the spirit

func (*SpiritDAOMock) UpsertSpirit

func (s *SpiritDAOMock) UpsertSpirit(ID string, spirit *model.Spirit) (bool, error)

UpsertSpirit updates or creates a spirit

type SpiritDAOMongo

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

SpiritDAOMongo is the mongo implementation of the SpiritDAO

func (*SpiritDAOMongo) DeleteSpirit

func (s *SpiritDAOMongo) DeleteSpirit(ID string) error

DeleteSpirit deletes a spirits by its ID

func (*SpiritDAOMongo) GetAllSpirits

func (s *SpiritDAOMongo) GetAllSpirits(start, end int) ([]model.Spirit, error)

GetAllSpirits returns all spirits with paging capability

func (*SpiritDAOMongo) GetSpiritByID

func (s *SpiritDAOMongo) GetSpiritByID(ID string) (*model.Spirit, error)

GetSpiritByID returns a spirit by its ID

func (*SpiritDAOMongo) GetSpiritsByName

func (s *SpiritDAOMongo) GetSpiritsByName(name string) ([]model.Spirit, error)

GetSpiritsByName returns all spirits by name

func (*SpiritDAOMongo) GetSpiritsByType

func (s *SpiritDAOMongo) GetSpiritsByType(spiritType string) ([]model.Spirit, error)

GetSpiritsByType returns all spirits by type

func (*SpiritDAOMongo) GetSpiritsByTypeAndScore

func (s *SpiritDAOMongo) GetSpiritsByTypeAndScore(spiritType string, score uint8) ([]model.Spirit, error)

GetSpiritsByTypeAndScore returns all spirits by type and score greater than parameter

func (*SpiritDAOMongo) SaveSpirit

func (s *SpiritDAOMongo) SaveSpirit(spirit *model.Spirit) error

SaveSpirit saves the spirit

func (*SpiritDAOMongo) UpsertSpirit

func (s *SpiritDAOMongo) UpsertSpirit(ID string, spirit *model.Spirit) (bool, error)

UpsertSpirit updates or creates a spirit

Jump to

Keyboard shortcuts

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