task

Reads and writes the tasks table: listing, creation, updates, status counts and id prefix lengths.

const SELECT_COLUMNS

source

pub(in crate::store::repo) const SELECT_COLUMNS: &str = "\
  id, project_id, title, priority, status, description, \
  assigned_to, metadata, resolved_at, created_at, updated_at";

The columns of tasks, in the order that the task model’s TryFrom<Row> reads them.

fn all

source

pub async fn all(conn: &Connection, project_id: &Id, filter: &Filter) -> Result<Vec<Model>, Error>

Return tasks for a project, applying the given filter.

Tasks that are done or cancelled are left out unless the filter asks for all. The newest come first.

Parameter Type Description
conn &Connection the database connection
project_id &Id the project whose tasks to list
filter &Filter whether to include resolved tasks, and an optional status, assignee name and tag label to match
returns Result<Vec<Model>, Error> The tasks, or an error when the query or a row’s decoding fails.

fn create

source

pub async fn create(conn: &Connection, project_id: &Id, new: &New) -> Result<Model, Error>

Create a new task in the given project.

The task gets a fresh id and timestamps set to now. Its status defaults to the default status, and resolved_at is set to now when the status is terminal. Metadata defaults to {}.

Parameter Type Description
conn &Connection the database connection
project_id &Id the project that owns the task
new &New the title, description, status, priority, assignee and metadata of the task
returns Result<Model, Error> The task as stored, or an error when the insert fails or the row cannot be read back.

fn find_by_id

source

pub async fn find_by_id(conn: &Connection, id: impl Into<Id>) -> Result<Option<Model>, Error>

Find a task by its Id.

Parameter Type Description
conn &Connection the database connection
id impl Into<Id> the full id of the task
returns Result<Option<Model>, Error> The task, None when no row has that id, or an error when the query fails.

fn find_required_by_id

source

pub async fn find_required_by_id(conn: &Connection, id: impl Into<Id>) -> Result<Model, Error>

Find a task by its Id, returning Error::NotFound when no row matches.

Parameter Type Description
conn &Connection the database connection
id impl Into<Id> the full id of the task
returns Result<Model, Error> The task, or a database error.

fn per_id_prefix_lengths

source

pub async fn per_id_prefix_lengths(
    conn: &Connection,
    project_id: &Id,
) -> Result<HashMap<String, usize>, Error>

Return per-ID prefix lengths for all tasks in the project using two-tier resolution: active (non-terminal) IDs are resolved against the active pool only, while terminal IDs are resolved against the full pool.

Parameter Type Description
conn &Connection the database connection
project_id &Id the project whose tasks form the pools
returns Result<HashMap<String, usize>, Error> Returns a HashMap<String, usize> mapping each full task ID to its minimum unique prefix length. It is an error when a query fails.

fn prefix_length_for_id

source

pub async fn prefix_length_for_id(
    conn: &Connection,
    project_id: &Id,
    id: &str,
) -> Result<usize, Error>

Return the minimum unique prefix length for a single task in the project.

Narrows the disambiguation pool to tasks whose ID shares at least the first character with id — an ID that differs at character 0 can never force the prefix longer than 1, so omitting it preserves the same result as per_id_prefix_lengths while avoiding a full-table scan.

Uses two-tier resolution: if the target is non-terminal it is resolved against the active pool only; otherwise it is resolved against the full pool, matching the semantics of per_id_prefix_lengths.

Parameter Type Description
conn &Connection the database connection
project_id &Id the project whose tasks form the pool
id &str the full encoded id of the task
returns Result<usize, Error> The length; 1 when id is empty.

fn status_counts

source

pub async fn status_counts(conn: &Connection, project_id: &Id) -> Result<StatusCounts, Error>

Return task counts grouped by status for a project in a single query.

Parameter Type Description
conn &Connection the database connection
project_id &Id the project whose tasks to count
returns Result<StatusCounts, Error> The returned StatusCounts includes every task in the project — active and terminal — so callers can render a summary row without issuing a second full-table scan. It holds the total too; a failed query is an error.

fn collect_ids

source

async fn collect_ids(conn: &Connection, sql: &str, project_id: &Id) -> Result<Vec<String>, Error>

Run a query that selects one id column, bound to a project id, and collect the ids.

Parameter Type Description
conn &Connection the database connection
sql &str a query whose first column is an id and whose ?1 is the project id
project_id &Id the value bound to ?1
returns Result<Vec<String>, Error> The ids, in the order the query returns them, or an error when the query fails.

fn update

source

pub async fn update(conn: &Connection, id: &Id, patch: &Patch) -> Result<Model, Error>

Update an existing task with the given patch.

Only the fields that the patch sets change; updated_at is always set to now. A status in the patch, even the current one, sets resolved_at to now when it is terminal and clears it otherwise.

Parameter Type Description
conn &Connection the database connection
id &Id the task to update
patch &Patch the fields to change, each optional; priority and assignee can also be cleared
returns Result<Model, Error> The updated task, or Error::NotFound when no task has that id.

fn record_update

source

pub async fn record_update(
    conn: &Connection,
    transaction_id: &Id,
    before: &Model,
    after: &Model,
) -> Result<(), Error>

Record the events for one update of a task, so gest undo can restore it.

A status change records a semantic completed, cancelled or status-change event, and a priority change a priority-change event, each carrying the row from before. An update that changed neither records a plain modified event.

Parameter Type Description
conn &Connection the database connection
transaction_id &Id the transaction the events belong to
before &Model the task before the update
after &Model the task after the update
returns Result<(), Error> Ok(()) once the events are recorded, or the database or serialization error.