db

package
v0.0.0-...-b9432f8 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusClosed    = "closed"
	StatusOpen      = "open"
	StatusDone      = "done"
	StatusOnHold    = "on_hold"
	StatusAbandoned = "abandoned"
)

These constants refer to the statuses supported by the app.

View Source
const MaxClosedTodos = 5

MaxClosedTodos defines the size of the closed todo list. This is intended to constrict work to items on this list, which encourages focus and prioritization.

Variables

View Source
var (
	// ErrMaxClosedTodos is returned from ChangeStatus when attempting to move a todo to the closed list when it is
	// full (i.e., it already has MaxClosedTodos todos).
	ErrMaxClosedTodos = fmt.Errorf(
		"there are already %d closed todos; complete or abandon something before starting something new",
		MaxClosedTodos,
	)
	// ErrInvalidTodoMoveNoStatusChange is returned from ChangeStatus when the old and new statuses are the same.
	ErrInvalidTodoMoveNoStatusChange = errors.New("cannot move a todo from one status to itself")

	// ErrInvalidTodoMove is returned from ChangeStatus when the old and new statuses are the same.
	ErrInvalidTodoMove = errors.New("cannot move a todo")
	// ErrCantMoveFirstTodoUp is returned from MoveUp when the first todo is moved up.
	ErrCantMoveFirstTodoUp = errors.New("cannot move up the first todo")
	// ErrCantMoveLastTodoDown is returned from MoveDown when the last todo is moved down.
	ErrCantMoveLastTodoDown = errors.New("cannot move down the last todo")
	// ErrNilTodo is returned when a modification is attempted on a nil Todo.
	ErrNilTodo = errors.New("no Todo is currently selected")
	// ErrEmptyTitle is returned when a new or modified todo has no title.
	ErrEmptyTitle = errors.New("Todo title cannot be empty")
)

Functions

This section is empty.

Types

type Database

type Database struct {
	Statuses map[string]*Status
	Labels   []*Label
	Todos    []*Todo
	// contains filtered or unexported fields
}

Database manages the db connection and the state of the system.

func NewDatabase

func NewDatabase(ctx context.Context, filename string) (*Database, error)

NewDatabase connects to the sqlite database at the given filename, initializes the structure if not present, and loads existing data into memory.

func (*Database) AddTodoLabel

func (d *Database) AddTodoLabel(ctx context.Context, todo *Todo, label *Label) error

AddTodoLabel adds a Label to a Todo.

func (*Database) ChangeStatus

func (d *Database) ChangeStatus(ctx context.Context, todo *Todo, oldStatus, newStatus *Status) error

ChangeStatus moves a Todo from one status to another.

func (*Database) Close

func (d *Database) Close() error

Close closes the database connection.

func (*Database) MoveDown

func (d *Database) MoveDown(ctx context.Context, todo *Todo) error

MoveDown moves a Todo one position down in the list, meaning it increases the ranking by 1 and reduces the ranking of the next Todo. If the last Todo is passed, return ErrCantMoveLastTodoDown.

func (*Database) MoveToBottom

func (d *Database) MoveToBottom(ctx context.Context, todo *Todo) error

MoveToBottom moves a Todo to the bottom of the list and moves everything else up (meaning it decreases all lower rankings by 1) If the last Todo is passed, return ErrCantMoveLastTodoDown.

func (*Database) MoveToTop

func (d *Database) MoveToTop(ctx context.Context, todo *Todo) error

MoveToTop moves a Todo to the top of the list and moves everything else down (meaning it increases all higher rankings by 1) If the first Todo is passed, return ErrCantMoveFirstTodoUp.

func (*Database) MoveUp

func (d *Database) MoveUp(ctx context.Context, todo *Todo) error

MoveUp moves a Todo one position up in the list, meaning it reduces the ranking by 1. and increases the ranking of the previous Todo. If the last Todo is passed, return ErrCantMoveFirstTodoUp.

func (*Database) NewLabel

func (d *Database) NewLabel(ctx context.Context, name string) (*Label, error)

NewLabel creates a new label with the given name.

func (*Database) NewTodo

func (d *Database) NewTodo(ctx context.Context, title, description string) (*Todo, error)

NewTodo creates a new Todo with the given title and description; the Todo is added at the end of the open list.

func (*Database) RemoveTodoLabel

func (d *Database) RemoveTodoLabel(ctx context.Context, todo *Todo, label *Label) error

RemoveTodoLabel removes a Label from a Todo.

func (*Database) UpdateLabel

func (d *Database) UpdateLabel(ctx context.Context, label *Label, name string) error

UpdateLabel updates the label name.

func (*Database) UpdateTodo

func (d *Database) UpdateTodo(ctx context.Context, todo *Todo, title, description string) error

UpdateTodo updates the Todo with the given title and description.

type Label

type Label struct {
	ID   int
	Name string
}

Label contains labels that can be applied to todos.

type Status

type Status struct {
	Name  string
	Todos []*Todo
	// contains filtered or unexported fields
}

Status represents a status entry and contains pointers to associated Todos.

type Todo

type Todo struct {
	Title       string
	Description string
	Labels      []*Label
	// Rank is maintained within each status. It starts at 0 and increments by 1.
	// When a Todo is moved to a different status, it is appended to the list, so it has the
	// highest rank in that list.
	Rank   int
	Status *Status
	// TODO (medium): populate timestamps!
	CreatedDatetime *time.Time
	UpdatedDatetime *time.Time
	// contains filtered or unexported fields
}

Todo contains individual todo entries and associated labels from the todo_labels table.

Jump to

Keyboard shortcuts

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