db

package
v0.0.0-...-ff9222e Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package db provides functions and data structures for manipulating local go boltdb database in terms of creating and editing tasks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTask

func AddTask(t *Task) error

AddTask saves Task in taskBucket under key equal to its id in form of JSON.

func DeleteTask

func DeleteTask(id int) error

DeleteTask removes task with given id from task bucket.

func InitDB

func InitDB(dbPath string) error

InitDB initialize default buckets in given path.

Types

type Checker

type Checker func(Task) bool

Checker chceks for specific informations about single task.

func IDChecker

func IDChecker(id int) Checker

IdChecker returns Checker which checks if id of Task is equal to given id.

func TagChecker

func TagChecker(tag string) Checker

TagChecker returns Checker which checks if Task contains given tag.

type Task

type Task struct {
	ID   int       `json:"id"`
	Body string    `json:"body"`
	Tags []string  `json:"tags"`
	Date time.Time `json:"date"`
}

Task represents single taks.

func GetAllTasks

func GetAllTasks() ([]Task, error)

GetAllTasks returns slice containing all Tasks from taskBucket.

func GetTask

func GetTask(id int) (Task, error)

GetTask returns task in form of Task struct from taskBucket under the key equal to given id.

func TaskFromJSON

func TaskFromJSON(JSONBytes []byte) (Task, error)

TaskFromJSON returns Task parsed from given bytes slice containg JSON.

func TaskSelection

func TaskSelection(tasks []Task, funcs ...Checker) []Task

TaskSelection applies given Checker funcs to slice of tasks and returns Task slice, which fullfils Checkers requirements.

func TasksFromJSON

func TasksFromJSON(JSONBytes []byte) ([]Task, error)

TasksFromJSON returns Task slice parsed from given bytes slice containg json.

func (*Task) ParseTags

func (t *Task) ParseTags(tagStr string, sep string)

ParseTags creates a list of strings (tags) from tags in string separated with given character.

func (*Task) ReadFromJSON

func (t *Task) ReadFromJSON(JSONBytes []byte) error

ReadFromJSON updates fields of Task with data from given []byte slice.

func (*Task) SetCurrDate

func (t *Task) SetCurrDate()

SetCurrDate updates Task time to current one.

func (Task) String

func (t Task) String() string

func (Task) ToJSON

func (t Task) ToJSON() ([]byte, error)

ToJSON returns the JSON encoding of task struct.

Jump to

Keyboard shortcuts

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