tasks

package
v0.0.0-...-436c719 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const NoID = 0

NoID is a reserved ID value.

Variables

View Source
var NoTime = time.Time{}

NoTime is a placeholder where a function is supposed to return a timestamp, but a meaningful value cannot be returned.

Functions

This section is empty.

Types

type DB

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

DB is a database connection.

func InitDatabase

func InitDatabase(path string) (*DB, error)

InitDatabase opens a database connection and creates the tables if needed.

func (*DB) AllTasks

func (db *DB) AllTasks() []Task

AllTasks returns every task from DB. Sorting order is not guaranteed.

func (*DB) Close

func (db *DB) Close() error

Close ends a database connection previously opened by `InitDatabase`. Should be called at the end of app lifespan.

func (*DB) Get

func (db *DB) Get(dest interface{}, query string, args ...interface{}) error

Get wraps sqlx.(*DB).Get, setting the DB reference if dest implements model.

func (*DB) LastMod

func (db *DB) LastMod() (time.Time, error)

LastMod returns the most recent task last mod timestamp, or zero value.

func (*DB) New

func (db *DB) New(id, pid int, text string) *Task

New creates a new task. Pass NoID for new tasks or tasks that have no parent.

func (*DB) ReplaceList

func (db *DB) ReplaceList(ts []Task) error

ReplaceList atomically replaces all tasks in the database with the new list in a single transaction.

func (*DB) RootTasks

func (db *DB) RootTasks() []Task

RootTasks returns all tasks that have no parent.

func (*DB) Select

func (db *DB) Select(dest interface{}, query string, args ...interface{}) error

Select wraps sqlx.(*DB).Select, setting DB references in slice objects if those implement model.

func (*DB) TaskByID

func (db *DB) TaskByID(id int) *Task

TaskByID returns a task by its ID.

func (*DB) TasksToRemove

func (db *DB) TasksToRemove() []Task

TasksToRemove returns every task that has ToRemove set.

func (*DB) TasksToSync

func (db *DB) TasksToSync() []Task

TasksToSync returns every task that has ToSync set.

type Task

type Task struct {
	ID        int       `db:"id"`
	PID       int       `db:"pid"`
	Text      string    `db:"ttext"`
	Completed bool      `db:"completed"`
	Ctime     time.Time `db:"ctime"`
	Mtime     time.Time `db:"mtime"`
	Deadline  time.Time `db:"deadline"`
	Reminder  time.Time `db:"reminder"`
	ToSync    bool      `db:"tosync"`
	ToRemove  bool      `db:"toremove"`
	// contains filtered or unexported fields
}

Task is a task model.

func (*Task) Add

func (t *Task) Add() error

Add adds the task to the database. If task ID is unset, the first available database ID is picked (as per rowid in SQLite).

func (*Task) Children

func (t *Task) Children() []Task

Children returns all tasks that have Task set as their parent ID.

func (Task) MarshalJSON

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

MarshalJSON implements json.Marshaler for Task.

func (*Task) Remove

func (t *Task) Remove() error

Remove removes a task from the DB.

func (*Task) SetPID

func (t *Task) SetPID(pid int) *Task

SetPID updates Task's PID. Use for chaining.

func (*Task) SetText

func (t *Task) SetText(text string) *Task

SetText updates task text. Use for chaining.

func (*Task) ToggleStatus

func (t *Task) ToggleStatus() *Task

ToggleStatus flips Task completed status. Use for chaining.

func (*Task) UnmarshalJSON

func (t *Task) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for Task.

func (*Task) UpMtime

func (t *Task) UpMtime() *Task

UpMtime sets Mtime to time.Now. Use for chaining.

func (*Task) Update

func (t *Task) Update() error

Update flushes new task data to the DB.

Jump to

Keyboard shortcuts

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