task

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2025 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package task provides core functionality for manging tasks in TidyTask.

It defines the Task struct, representing individual tasks. It also handles all CRUD operations relating to tasks.

Index

Constants

This section is empty.

Variables

View Source
var DB *sql.DB

DB is a global variable representing the database connection

Functions

func AddTask

func AddTask(t Task) error

AddTask inserts a new task into the tasks database table by taking in a task struct

func BackupDB

func BackupDB() error

BackupDB creates a backup copy of the current SQLite database file ("tasks.db"). It reads the original database file and writes its contents to a new file "tasks.db.bak".

func CheckTaskExists

func CheckTaskExists(id int) error

CheckTaskExists checks if a task with the given ID exists in the database. It returns an error if the task does not exist or if there is a query error.

func CloseDB

func CloseDB() error

CloseDB safely closes the database connection, if it had been opened. it returns any error encountered during close, and if the DB was never initialised, it returns nil this function is always called on exit of tidytask

func CompleteTask

func CompleteTask(id int) error

CompleteTask marks the task with the specified ID in the database as complete

func HardReset added in v1.0.1

func HardReset() error

HardReset deletes both the main database file and the backup file, if they exist.

func InitDB

func InitDB() error

InitDB creates the SQLite database by creating the database file and the tasks table if it does not exist

func RemoveTask

func RemoveTask(id int) error

RemoveTask deletes the task with the specified ID from the database.

func ReopenTask

func ReopenTask(id int) error

ReopenTask updates the task with the given ID to mark it as open (incomplete) it sets the 'complete' field to false and clears complete_date

func RestoreBackup

func RestoreBackup() error

RestoreBackup replaces the current database file with the backup copy. After successfully restoring, it deletes the backup file.

func SetDue

func SetDue(id int, newDate string) error

SetDue updates the due date of the task identified by the given ID. it sets the task's due field to the provided newDate string

func SetTitle

func SetTitle(id int, newTitle string) error

SetTitle updates the due date of the task identified by the given ID. it sets the task's title field to the provided newTitle string

func TogglePriority

func TogglePriority(id int) error

TogglePriority flips the priority status of the task identified by the given ID.

Types

type Task

type Task struct {
	ID           int            `json:"id"`            // Unique ID for task (primary key)
	Title        string         `json:"title"`         // Title or description of the task (mandatory)
	Due          string         `json:"due"`           // Due date as string (empty string represents no due set)
	Complete     bool           `json:"complete"`      // Flag indicating the tasks completion status
	CompleteDate sql.NullString `json:"complete_date"` // Nullable date string representing when task was completed
	Priority     bool           `json:"priority"`      // Flag indicating if the task is marked as high priority
}

Task represents a to-do list task

func GetTasks

func GetTasks() ([]Task, error)

GetTasks retrieves all tasks from the database and returns them as a slice of Task structs. tasks are ordered by completion status, priority, presence of a due date, and due date ascending.

func SearchTasks

func SearchTasks(keyword string, searchID bool, searchTitle bool, searchDue bool) ([]Task, error)

SearchTasks searches the tasks database for tasks where the given keyword matches any of the specified fields Returns a slice of matching Task structs or an error if the query fails

Jump to

Keyboard shortcuts

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