Documentation ¶
Index ¶
- Constants
- Variables
- func BackupDatabase(input, output string) error
- type Project
- type Store
- func (store *Store) Close()
- func (store *Store) CompleteTaskById(taskId int64) (bool, error)
- func (store *Store) CountTasks(ctx context.Context) (int64, error)
- func (store *Store) CreateTask(ctx context.Context, task *Task) (*Task, error)
- func (store *Store) DecreasePriority(ctx context.Context, id int64) (bool, error)
- func (store *Store) DeleteDependenciesForCompletedTask(completedTaskId int64) error
- func (store *Store) DeleteTaskById(ctx context.Context, id int64) (bool, error)
- func (store *Store) FilterByTaskId(taskId int64, tasks []TaskDetailed) *TaskDetailed
- func (store *Store) GetCumTime(ctx context.Context, taskId int64) (int64, error)
- func (store *Store) GetDependenciesForTask(taskId int64) ([]TaskDependency, error)
- func (store *Store) GetTaskById(ctx context.Context, taskId int64) (*Task, error)
- func (store *Store) GetTaskByIdOrPanic(id int64) *Task
- func (store *Store) GetTaskTimes(ctx context.Context, taskId int64) ([]TaskTime, error)
- func (store *Store) IncreasePriority(ctx context.Context, id int64) (bool, error)
- func (store *Store) IsConnected() bool
- func (s *Store) ListProjects() ([]Project, error)
- func (store *Store) ListTasks(ctx context.Context) ([]TaskDetailed, error)
- func (store *Store) MustCreateTxTodo() *sqlx.Tx
- func (s *Store) ProjectGetIDByNameOrCreateTx(tx *sqlx.Tx, title string) (int64, error)
- func (s *Store) ProjectLinkTaskTx(tx *sqlx.Tx, projectId, taskId int64) error
- func (s *Store) ProjectTasksList() ([]TaskProjectLink, error)
- func (store *Store) RunMigrations() error
- func (store *Store) SchemaVersion() int
- func (store *Store) SetPriority(ctx context.Context, id int64, priority TaskPriority) (bool, error)
- func (store *Store) SetTaskState(taskId int64, state TaskState) error
- func (store *Store) SetTaskStateToCompleted(taskId int64) error
- func (store *Store) SetTaskStateToIncomplete(taskId int64) error
- func (store *Store) SetTaskStateToStarted(taskId int64) error
- func (store *Store) StartTrackingTaskTime(ctx context.Context, taskId int64) error
- func (store *Store) StopTrackingTaskTime(ctx context.Context, id int64) error
- func (store *Store) TagCreate(ctx context.Context, name string) (int64, error)
- func (store *Store) TagCreateTx(name string, tx *sqlx.Tx) (int64, error)
- func (store *Store) TagGetByName(name string) (*Tag, error)
- func (store *Store) TagGetByNameTx(name string, tx *sqlx.Tx) (*Tag, error)
- func (store *Store) TagLinkTaskCtx(ctx context.Context, taskId, tagId int64) error
- func (store *Store) TagLinkTaskTx(tx *sqlx.Tx, taskId, tagId int64) error
- func (store *Store) TagList(ctx context.Context) ([]Tag, error)
- func (store *Store) TagUnlinkTask(taskId, tagId int64) error
- func (store *Store) TagUnlinkTaskTx(tx *sqlx.Tx, taskId, tagId int64) error
- func (store *Store) TaskDependsOnTx(tx *sqlx.Tx, taskId int64, dependsOnId int64) error
- func (store *Store) TaskIdExistsAndNotCompleted(tx *sqlx.Tx, taskId int64) bool
- func (store *Store) TaskToggleNextTx(tx *sqlx.Tx, taskId int64) error
- type Tag
- type Task
- type TaskDependency
- type TaskDetailed
- func (task *TaskDetailed) IsStarted() bool
- func (task *TaskDetailed) PrettyCumTime() string
- func (task *TaskDetailed) Urgency() float64
- func (task *TaskDetailed) UrgencyColourAnsiBackground() string
- func (task *TaskDetailed) UrgencyColourAnsiForeground() string
- func (task *TaskDetailed) UrgencyStr() string
- type TaskPriority
- type TaskProjectLink
- type TaskState
- type TaskTag
- type TaskTime
- type UrgencyCoefficient
Constants ¶
const EPSILION = 0.000001
const M000_TaskSchema = `` /* 406-byte string literal not displayed */
const M001_TagSchema = `` /* 129-byte string literal not displayed */
const M002_TaskTagsSchema = `` /* 291-byte string literal not displayed */
const M003_TaskSchema = `
ALTER TABLE tasks ADD COLUMN startedAtUtc TEXT;
PRAGMA user_version = 3;
`
const M004_TaskSchema = `
ALTER TABLE tasks ADD COLUMN state INTEGER NOT NULL DEFAULT 0 CHECK (state >= 0 AND state <= 2);
PRAGMA user_version = 4;
`
const M005_TaskSchema = `
ALTER TABLE tasks DROP COLUMN completed;
PRAGMA user_version = 5;
`
const M006_ProjectSchema = `` /* 127-byte string literal not displayed */
const M007_TaskProjectsSchema = `` /* 318-byte string literal not displayed */
const M008_TimeTrackingSchema = `` /* 282-byte string literal not displayed */
const M009_TaskSchema = `
ALTER TABLE tasks DROP COLUMN startedAtUtc;
PRAGMA user_version = 9;
`
const M010_TaskDependenciesSchema = `` /* 292-byte string literal not displayed */
const M011_TaskSchema = `
ALTER TABLE tasks ADD COLUMN next INTEGER NOT NULL DEFAULT 0 CHECK (next >= 0 AND next <= 1);
PRAGMA user_version = 11;
`
const SQLITE_TIME_FORMAT = "2006-01-02 15:04:05" // SQLite's default timestamp format
const URGENCY_MAX_AGES = time.Duration(365 * 24 * time.Hour)
Variables ¶
var Migrations = []string{ M000_TaskSchema, M001_TagSchema, M002_TaskTagsSchema, M003_TaskSchema, M004_TaskSchema, M005_TaskSchema, M006_ProjectSchema, M007_TaskProjectsSchema, M008_TimeTrackingSchema, M009_TaskSchema, M010_TaskDependenciesSchema, M011_TaskSchema, "PRAGMA foreign_keys = ON", }
Migrations contains all the migrations that need to be run. Each migration is a SQL statement. The migrations are run in order.
Functions ¶
func BackupDatabase ¶
BackupDatabase copies the SQLite database file from input to output. This will overwrite any previous backups
Types ¶
type Project ¶
type Project struct { ID int64 `db:"id"` // Unique identifier Title string `db:"title"` // Project title }
A project may be assigned to a task, and that project may be multiple words.
type Store ¶
Store is a wrapper around the database connection
func NewInMemoryStore ¶
func NewInMemoryStore() *Store
NewInMemoryStore creates a new in-memory store, useful for testing
func NewStore ¶
func NewStore(conf *config.SqlConnectionConfig) (*Store, error)
NewStore creates a new store with the given configuration
func (*Store) CompleteTaskById ¶
CompleteTaskById marks a task as completed by its ID
func (*Store) CountTasks ¶
CountTasks returns the total number of tasks in the database
func (*Store) CreateTask ¶
CreateTask creates a new task in the database
func (*Store) DecreasePriority ¶
DecreasePriority decreases the priority of a task by its ID (if possible)
func (*Store) DeleteDependenciesForCompletedTask ¶
DeleteDependenciesForTask deletes all dependencies for a task
func (*Store) DeleteTaskById ¶
DeleteTaskById deletes a task by its ID
func (*Store) FilterByTaskId ¶
func (store *Store) FilterByTaskId(taskId int64, tasks []TaskDetailed) *TaskDetailed
FilterByTaskId returns a task by its ID
func (*Store) GetCumTime ¶
GetCumTime will get the cumulative time for a task
func (*Store) GetDependenciesForTask ¶
func (store *Store) GetDependenciesForTask(taskId int64) ([]TaskDependency, error)
GetDependenciesForTask returns all the dependencies for a task
func (*Store) GetTaskById ¶
GetTaskById returns a task by its ID
func (*Store) GetTaskByIdOrPanic ¶
GetTaskByIdOrPanic returns a task by its ID or panics (ONLY FOR TESTING)
func (*Store) GetTaskTimes ¶
GetTaskTimes will get all the times for a task
func (*Store) IncreasePriority ¶
IncreasePriority increases the priority of a task by its ID (if possible)
func (*Store) IsConnected ¶
IsConnected returns true if the store is connected to the database
func (*Store) ListProjects ¶
ListProjects returns a list of all projects.
func (*Store) ListTasks ¶
func (store *Store) ListTasks(ctx context.Context) ([]TaskDetailed, error)
ListTasks returns a list of all tasks in the database
func (*Store) MustCreateTxTodo ¶
func (*Store) ProjectGetIDByNameOrCreateTx ¶
ProjectGetIDByNameOrCreate will get the project ID by name or create it if it does not exist.
func (*Store) ProjectLinkTaskTx ¶
ProjectLinkTaskTx will link a task to a project
func (*Store) ProjectTasksList ¶
func (s *Store) ProjectTasksList() ([]TaskProjectLink, error)
ProjectUnlinkTaskTx will unlink a task from a project
func (*Store) RunMigrations ¶
RunMigrations runs all migrations that have not been run. The PRAGMA user_version is used to determine the current schema version. If the schema version is less than the migration index, the migration is run. If the schema version is greater than the migration index, the migration is skipped.
func (*Store) SchemaVersion ¶
SchemaVersion returns the current schema version. The schema version is stored in the PRAGMA user_version.
func (*Store) SetPriority ¶
SetPriority sets the priority of a task by its ID
func (*Store) SetTaskState ¶
SetTaskState sets the state of a task by its ID
func (*Store) SetTaskStateToCompleted ¶
SetTaskStateToCompleted marks a task as completed by its ID
func (*Store) SetTaskStateToIncomplete ¶
SetTaskStateToIncomplete marks a task as incomplete by its ID
func (*Store) SetTaskStateToStarted ¶
SetTaskStateToCompleted marks a task as completed by its ID
func (*Store) StartTrackingTaskTime ¶
StartTrackingTaskTime will start tracking time for a task
func (*Store) StopTrackingTaskTime ¶
StopTrackingTaskTime will stop tracking time for a task
func (*Store) TagCreateTx ¶
CreateTagTx will create a new in the database (this should not exist) the transaction is NOT rolled back on err
func (*Store) TagGetByName ¶
GetTagByName will get a single row for the tag with the name specified
func (*Store) TagGetByNameTx ¶
GetTagByNameTx will get a single row for the tag with then name specified NOTE: the transaction is not rolled back on error
func (*Store) TagLinkTaskCtx ¶
TagLinkTask will link a task to a tag
func (*Store) TagLinkTaskTx ¶
TagLinkTaskTx will link a task to a tag inside of a transaction
func (*Store) TagUnlinkTask ¶
TagUnlinkTask will unlink a tag
func (*Store) TagUnlinkTaskTx ¶
TagUnlinkTask will unlink a tag inside of a transaction
func (*Store) TaskDependsOnTx ¶
TaskDependsOn creates a dependency between two tasks
func (*Store) TaskIdExistsAndNotCompleted ¶
TaskIdExistsAndNotCompleted returns true if a task exists and is not completed
type Tag ¶
type Tag struct { ID int `json:"id" db:"id"` // Unique identifier of the tag Name string `json:"name" db:"name"` // Name of the tag }
Tag is a struct that represents a tag e.g "+work"
type Task ¶
type Task struct { ID int64 `json:"id" db:"id"` // ID of the task Title string `json:"title" db:"title"` // Title of the task Priority TaskPriority `json:"priority" db:"priority"` // Priority of the task CreatedUtc string `json:"createdUtc" db:"createdAtUtc"` // Created timestamp State TaskState `json:"state" db:"state"` // State of the task Description sql.NullString `json:"description" db:"description"` // Optional Description of the task (this is not the title) Due sql.NullString `json:"due" db:"dueUtc"` // Optional Due Date UpdatedAtUtc sql.NullString `json:"updatedAtUtc" db:"updatedAtUtc"` // Optional UpdatedAtUtc CompletedUtc sql.NullString `json:"completedUtc" db:"completedAtUtc"` // Set once the task is marked as complete Next bool `json:"next" db:"next"` // If the tasks is flaged as next to be started on }
Task represents a task in the database
func (*Task) PriorityStr ¶
PriorityStr returns the string version of the Priority Int
type TaskDependency ¶
type TaskDetailed ¶
type TaskDetailed struct { Task ProjectCount int `json:"projectCount" db:"projectCount"` // The number of projects the task is associated with ProjectNames sql.NullString `json:"projectNames" db:"projectNames"` // The names of projects the task is associated joined using commas TagCount int `json:"tagCount" db:"tagCount"` // The number of tags the task is associated with TagNames sql.NullString `json:"tagNames" db:"tagNames"` // The names of tags the task is associated joined using commas FirstStartedUtc sql.NullString `json:"firstStartedUtc" db:"firstStartedUtc"` // When the task was first started (if it ever was) CumulativeTime sql.NullString `json:"cumulativeTime" db:"cumulativeTime"` // Total time spent on task throughout multiple sessions Inprogress bool `json:"inprogress" db:"inprogress"` // If the task is inprogress Dependencies sql.NullString `json:"dependencies" db:"dependencies"` // Comma serperated list of Dependencies Blocked bool `json:"blocked" db:"blocked"` // If the current task has unmet Dependencies Blocking int `json:"blocking" db:"blocking"` // The total number of tasks that this task is blocking // contains filtered or unexported fields }
TaskDetailed represents a task with additional information from other tables
func (*TaskDetailed) IsStarted ¶
func (task *TaskDetailed) IsStarted() bool
IsStarted returns true if the task is in progress
func (*TaskDetailed) PrettyCumTime ¶
func (task *TaskDetailed) PrettyCumTime() string
PrettyCumTime returns the pretty version of the CumulativeTime
func (*TaskDetailed) Urgency ¶
func (task *TaskDetailed) Urgency() float64
Urgency returns the urgency of the task based on the task's properties (will be cached)
func (*TaskDetailed) UrgencyColourAnsiBackground ¶
func (task *TaskDetailed) UrgencyColourAnsiBackground() string
UrgencyColourAnsiBackground returns the ANSI background colour for the task urgency
func (*TaskDetailed) UrgencyColourAnsiForeground ¶
func (task *TaskDetailed) UrgencyColourAnsiForeground() string
UrgencyColourAnsiForeground returns the ANSI foreground colour for the task urgency
func (*TaskDetailed) UrgencyStr ¶
func (task *TaskDetailed) UrgencyStr() string
UrgencyStr returns the string version of the Urgency Float
type TaskPriority ¶
type TaskPriority int // Task priority levels
const ( TaskPriorityNone TaskPriority = iota // Default priority TaskPriorityLow TaskPriorityMedium TaskPriorityHigh )
type TaskProjectLink ¶
TaskProjectLink is a struct that represents a link between a task and a project
type TaskTag ¶
type TaskTag struct { ID int `json:"id" db:"id"` // Unique identifier of the task-tag link TaskID int `json:"taskID" db:"taskID"` // ID of the task TagID int `json:"tagID" db:"tagID"` // ID of the tag }
Used to link tasks and tags together
type TaskTime ¶
type TaskTime struct { Id int64 `db:"id"` // Unique identifier TaskId int64 `db:"taskId"` // Unique identifier of the task StartTimeUtc string `db:"startTimeUtc"` // Start time in UTC EndTimeUtc sql.NullString `db:"endTimeUtc"` // End time in UTC TotalTime sql.NullString `db:"totalTime"` // Total time in seconds }
TaskTime represents the time tracking for a task
type UrgencyCoefficient ¶
type UrgencyCoefficient float64 // Used to calculate task urgency
const ( URGENCY_NEXT_TAG_COEFFICIENT UrgencyCoefficient = 15.0 // +Next URGENCY_PRIORITY_HIGH_COEFFICIENT UrgencyCoefficient = 4.0 // P:High URGENCY_PRIORITY_MEDIUM_COEFFICIENT UrgencyCoefficient = 2.0 // P:Med URGENCY_PRIORITY_LOW_COEFFICIENT UrgencyCoefficient = 1.0 // P:Low URGENCY_PRIORITY_NONE_COEFFICIENT UrgencyCoefficient = 0.0 // P:None URGENCY_DUE_COEFFICIENT UrgencyCoefficient = 12.0 // Due:now URGENCY_BLOCKING_COEFFICIENT UrgencyCoefficient = 8.0 // Task Dependencies URGENCY_ACTIVE_COEFFICIENT UrgencyCoefficient = 20.0 // Task is started URGENCY_SCHEDULED_COEFFICIENT UrgencyCoefficient = 5.0 // Task is scheduled URGENCY_PROJECT_COEFFICIENT UrgencyCoefficient = 1.0 // Task has project URGENCY_BLOCKED_COEFFICIENT UrgencyCoefficient = -5.0 // Task is blocked )