dao

package
v0.0.0-...-10f03cb Latest Latest
Warning

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

Go to latest
Published: May 14, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

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

Variables

View Source
var (
	// ErrInvalidUUID is used on invalid UUID number
	ErrInvalidUUID = errors.New("invalid input to UUID")

	// ErrNotFound is used when no result are found for the given parameters
	ErrNotFound = errors.New("no result found")
)
View Source
var (
	// ErrorDAONotFound is used for unknown DAO type
	ErrorDAONotFound = errors.New("unknown DAO type")
)
View Source
var MockedTask = model.Task{
	ID:           uuid.NewV4().String(),
	Title:        "Learn Go",
	Description:  "Let's learn the Go programming language and how to use it in a real project to make great programs.",
	Status:       model.StatusInProgress,
	Priority:     model.PriorityHigh,
	CreationDate: time.Date(2017, 01, 01, 0, 0, 0, 0, time.UTC),
	DueDate:      time.Date(2017, 01, 02, 0, 0, 0, 0, time.UTC),
}

MockedTask is the task returned by this mocked interface

Functions

This section is empty.

Types

type DBType

type DBType int

DBType lists the type of implementation the factory can return

const (
	// DAOMongo is used for Mongo implementation of TaskDAO
	DAOMongo DBType = iota
	// DAOPostgres is used for PostgreSQL implementation of TaskDAO
	DAOPostgres
	// DAOMock is used for mocked implementation of TaskDAO
	DAOMock

	// DAOMockStr is the string representation of the DAOMock DBType
	DAOMockStr = "mock"
)

func ParseDBType

func ParseDBType(dbType string) (DBType, error)

ParseDBType parses the string representation and returns the DBType or an error

type TaskDAO

type TaskDAO interface {

	// GetByID returns a task by its ID
	GetByID(ID string) (*model.Task, error)

	// GetAll returns all tasks with paging capability
	GetAll(start, end int) ([]model.Task, error)

	// GetByTitle returns all tasks by title
	GetByTitle(title string) ([]model.Task, error)

	// GetByStatus returns all tasks by status
	GetByStatus(status model.TaskStatus) ([]model.Task, error)

	// GetByStatusAndPriority returns all tasks by status and priority
	GetByStatusAndPriority(status model.TaskStatus, priority model.TaskPriority) ([]model.Task, error)

	// Save saves the task
	Save(task *model.Task) error

	// Upsert updates or creates a task, returns true if updated, false otherwise or on error
	Upsert(task *model.Task) (bool, error)

	// Delete deletes a tasks by its ID
	Delete(ID string) error
}

TaskDAO is the DAO interface to work with tasks

func GetTaskDAO

func GetTaskDAO(cnxStr, migrationPath string, daoType DBType) (TaskDAO, error)

GetTaskDAO returns a TaskDAO according to type and params

func NewTaskDAOMock

func NewTaskDAOMock() TaskDAO

NewTaskDAOMock creates a new TaskDAO with a mocked implementation

func NewTaskDAOMongo

func NewTaskDAOMongo(session *mgo.Session) TaskDAO

NewTaskDAOMongo creates a new TaskDAO mongo implementation

func NewTaskDAOPostgres

func NewTaskDAOPostgres(db *sql.DB) TaskDAO

NewTaskDAOPostgres creates a new TaskDAO postgreSQL implementation

type TaskDAOMock

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

TaskDAOMock is the mocked implementation of the TaskDAO

func (*TaskDAOMock) Delete

func (s *TaskDAOMock) Delete(ID string) error

Delete deletes a tasks by its ID

func (*TaskDAOMock) GetAll

func (s *TaskDAOMock) GetAll(start, end int) ([]model.Task, error)

GetAll returns all tasks with paging capability

func (*TaskDAOMock) GetByID

func (s *TaskDAOMock) GetByID(ID string) (*model.Task, error)

GetByID returns a task by its ID

func (*TaskDAOMock) GetByStatus

func (s *TaskDAOMock) GetByStatus(status model.TaskStatus) ([]model.Task, error)

GetByStatus returns all tasks by status

func (*TaskDAOMock) GetByStatusAndPriority

func (s *TaskDAOMock) GetByStatusAndPriority(status model.TaskStatus, priority model.TaskPriority) ([]model.Task, error)

GetByStatusAndPriority returns all tasks by status and priority

func (*TaskDAOMock) GetByTitle

func (s *TaskDAOMock) GetByTitle(title string) ([]model.Task, error)

GetByTitle returns all tasks by title

func (*TaskDAOMock) Save

func (s *TaskDAOMock) Save(task *model.Task) error

Save saves the task

func (*TaskDAOMock) Upsert

func (s *TaskDAOMock) Upsert(task *model.Task) (bool, error)

Upsert updates or creates a task

type TaskDAOMongo

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

TaskDAOMongo is the mongo implementation of the TaskDAO

func (*TaskDAOMongo) Delete

func (s *TaskDAOMongo) Delete(ID string) error

Delete deletes a tasks by its ID

func (*TaskDAOMongo) GetAll

func (s *TaskDAOMongo) GetAll(start, end int) ([]model.Task, error)

GetAll returns all tasks with paging capability

func (*TaskDAOMongo) GetByID

func (s *TaskDAOMongo) GetByID(ID string) (*model.Task, error)

GetByID returns a task by its ID

func (*TaskDAOMongo) GetByStatus

func (s *TaskDAOMongo) GetByStatus(status model.TaskStatus) ([]model.Task, error)

GetByStatus returns all tasks by status

func (*TaskDAOMongo) GetByStatusAndPriority

func (s *TaskDAOMongo) GetByStatusAndPriority(status model.TaskStatus, priority model.TaskPriority) ([]model.Task, error)

GetByStatusAndPriority returns all tasks by status and priority

func (*TaskDAOMongo) GetByTitle

func (s *TaskDAOMongo) GetByTitle(title string) ([]model.Task, error)

GetByTitle returns all tasks by title

func (*TaskDAOMongo) Save

func (s *TaskDAOMongo) Save(task *model.Task) error

Save saves the task

func (*TaskDAOMongo) Upsert

func (s *TaskDAOMongo) Upsert(task *model.Task) (bool, error)

Upsert updates or creates a task, returns true if updated, false otherwise or on error

type TaskDAOPostgres

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

TaskDAOPostgres is the postgreSQL implementation of the TaskDAO

func (*TaskDAOPostgres) Delete

func (s *TaskDAOPostgres) Delete(ID string) error

Delete deletes a tasks by its ID

func (*TaskDAOPostgres) GetAll

func (s *TaskDAOPostgres) GetAll(start, end int) ([]model.Task, error)

GetAll returns all tasks with paging capability

func (*TaskDAOPostgres) GetByID

func (s *TaskDAOPostgres) GetByID(ID string) (*model.Task, error)

GetByID returns a task by its ID

func (*TaskDAOPostgres) GetByStatus

func (s *TaskDAOPostgres) GetByStatus(status model.TaskStatus) ([]model.Task, error)

GetByStatus returns all tasks by status

func (*TaskDAOPostgres) GetByStatusAndPriority

func (s *TaskDAOPostgres) GetByStatusAndPriority(status model.TaskStatus, priority model.TaskPriority) ([]model.Task, error)

GetByStatusAndPriority returns all tasks by status and priority

func (*TaskDAOPostgres) GetByTitle

func (s *TaskDAOPostgres) GetByTitle(title string) ([]model.Task, error)

GetByTitle returns all tasks by title

func (*TaskDAOPostgres) Save

func (s *TaskDAOPostgres) Save(task *model.Task) error

Save saves the task

func (*TaskDAOPostgres) Upsert

func (s *TaskDAOPostgres) Upsert(task *model.Task) (bool, error)

Upsert updates or creates a task, returns true if updated, false otherwise or on error

Jump to

Keyboard shortcuts

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