database

package
v0.0.0-...-1f420dc Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidID   = errors.New("Task has an invalid ID")
	ErrMissingTask = errors.New("No such task")
	ErrTaskCycle   = errors.New("A task cycle would be created")
)
View Source
var (
	ErrFailedToCreate = errors.New("Failed to create database")
)

Functions

This section is empty.

Types

type Database

type Database interface {
	// Children recursively traverses the graph of tasks
	// and returns all tasks which are the children
	// of the task belonging to the provided ID.
	//
	// If the provided ID is invalid (aka, empty and would produce ""),
	// this should return `ErrInvalidID`.
	//
	// If no such task exists, or that task is already deleted,
	// this should return `ErrMissingTask`.
	Children(id uuid.UUID) ([]models.Task, error)

	// Complete marks the task belonging to the provided ID as complete.
	//
	// If the provided ID is invalid (aka, empty and would produce ""),
	// this should return `ErrInvalidID`.
	//
	// If no such task exists, or that task is already deleted,
	// this should return `ErrMissingTask`.
	Complete(id uuid.UUID) error

	// Delete marks the task belonging to the provided ID as deleted.
	//
	// If the provided ID is invalid (aka, empty and would produce ""),
	// this should return `ErrInvalidID`.
	//
	// If no such task exists this should return `ErrMissingTask`.
	Delete(id uuid.UUID) error

	// Get returns the models.Task belonging to the provided ID.
	//
	// If the provided ID is invalid (aka, empty and would produce ""),
	// this should return `ErrInvalidID`.
	//
	// If no such task exists this should return `ErrMissingTask`.
	Get(id uuid.UUID) (models.Task, error)

	// GetAll returns every `models.Task` which is active
	// (not completed, not deleted).
	GetAll() ([]models.Task, error)

	// Goals returns the set of `models.Task`s which are parents of other tasks,
	// but are not depended on by another tasks.
	Goals() ([]models.Task, error)

	// Inbox returns the set of `models.Task`s which are
	// neither parents nor children of other tasks.
	Inbox() ([]models.Task, error)

	// Link inserts a connection between the task belonging to `parentID`
	// and the task belonging to `childID`.
	//
	// If linking this parent/child pair would create a cycle in the task graph
	// this function should return `ErrTaskCycle`.
	Link(parentID uuid.UUID, childID uuid.UUID) error

	// Todo recursively traverses the graph of tasks
	// and returns all leaf tasks in which children
	// of the task belonging to `id`.
	//
	// If the provided ID is invalid (aka, empty and would produce ""),
	// this should return `ErrInvalidID`.
	//
	// If no such task exists, or that task is already deleted,
	// this should return `ErrMissingTask`.
	Todo(id uuid.UUID) ([]models.Task, error)

	// Unlinks removes a link between the task belonging to `parentID`
	// and the task belonging to `childID`.
	Unlink(parentID uuid.UUID, childID uuid.UUID) error

	// Upsert inserts or replaces the provided task in the database.
	Upsert(task models.Task) error
}

type SQLiteDatabase

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

func OpenSQLite

func OpenSQLite(path string) (*SQLiteDatabase, error)

func (*SQLiteDatabase) Children

func (db *SQLiteDatabase) Children(id uuid.UUID) ([]models.Task, error)

func (*SQLiteDatabase) Complete

func (db *SQLiteDatabase) Complete(id uuid.UUID) error

func (*SQLiteDatabase) Delete

func (db *SQLiteDatabase) Delete(id uuid.UUID) error

func (*SQLiteDatabase) Get

func (db *SQLiteDatabase) Get(id uuid.UUID) (models.Task, error)

Get retrieves a Task from the database with the provided ID. If the UUID is invalid, or there is no

func (*SQLiteDatabase) GetAll

func (db *SQLiteDatabase) GetAll() ([]models.Task, error)

GetAll returns the total set of Tasks in the database. This is useful when one wants to perform a search over all possible tasks.

func (*SQLiteDatabase) Goals

func (db *SQLiteDatabase) Goals() ([]models.Task, error)

func (*SQLiteDatabase) Inbox

func (db *SQLiteDatabase) Inbox() ([]models.Task, error)
func (db *SQLiteDatabase) Link(parentID uuid.UUID, childID uuid.UUID) error

Link links together two tasks, such that the task belonging to parentID is marked as depending on the task belonging to childID.

func (*SQLiteDatabase) Migrate

func (db *SQLiteDatabase) Migrate() error

func (*SQLiteDatabase) Todo

func (db *SQLiteDatabase) Todo(id uuid.UUID) ([]models.Task, error)

Todo returns all of all of the leaf nodes reachable by the provided id. This corresponds to tasks related to the provided task which are actionable.

func (db *SQLiteDatabase) Unlink(parentID uuid.UUID, childID uuid.UUID) error

func (*SQLiteDatabase) Upsert

func (db *SQLiteDatabase) Upsert(task models.Task) error

Upsert performs an update/insert on the provided Task. The `task` must at least have its `uuid` populated. All columns will be replaced with the contents of the Task, even if they are empty.

Jump to

Keyboard shortcuts

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