Skip to main content

Tasks

Struct Tasks 

Source
pub struct Tasks {
    pub conn: Connection,
    pub id: Option<i32>,
}
Expand description

Task table access; remembers the last inserted id for chaining.

Fields§

§conn: Connection§id: Option<i32>

Id of the most recently inserted task, for update_id/get chaining.

Implementations§

Source§

impl Tasks

Source

pub fn new() -> Result<Self>

Opens the database and ensures the tasks table exists.

use kasl::db::tasks::Tasks;

let mut tasks = Tasks::new()?;
Source

pub fn insert(&mut self, task: &Task) -> Result<&mut Self>

Inserts the task, storing the assigned id for chaining.

use kasl::db::tasks::Tasks;
use kasl::libs::task::Task;

let mut tasks = Tasks::new()?;
let task = Task::new("Code review", "Review PR #123", Some(50));
tasks.insert(&task)?
     .update_id()?; // Method chaining
Source

pub fn update_id(&mut self) -> Result<&mut Self>

Points the just-inserted task’s task_id at its own id - the convention for a standalone task that groups its own history.

use kasl::libs::task::Task;

let mut tasks = Tasks::new()?;
let subtask = Task::new("Subtask", "Part of larger task", Some(0));
tasks.insert(&subtask)?
     .update_id()?;
Source

pub fn get(&mut self) -> Result<Vec<Task>>

Fetches the most recently inserted task.

use kasl::libs::task::Task;

let mut tasks = Tasks::new()?;
let task = Task::new("New task", "Description", Some(100));
let inserted_tasks = tasks.insert(&task)?
                         .get()?;
Source

pub fn fetch(&mut self, filter: TaskFilter) -> Result<Vec<Task>>

Runs the query for the given filter and attaches each task’s tags.

use kasl::db::tasks::Tasks;
use kasl::libs::task::TaskFilter;
use chrono::Local;

let mut tasks = Tasks::new()?;

let all_tasks = tasks.fetch(TaskFilter::All)?;
let today = tasks.fetch(TaskFilter::Date(Local::now().date_naive()))?;
let urgent = tasks.fetch(TaskFilter::ByTag("urgent".to_string()))?;
let incomplete = tasks.fetch(TaskFilter::Incomplete)?;
Source

pub fn delete(&mut self, id: i32) -> Result<usize>

Deletes one task; returns the number of rows removed.

let mut tasks = Tasks::new()?;
let task_id = 1;
let deleted_count = tasks.delete(task_id)?;
if deleted_count > 0 {
    println!("Task deleted successfully");
}
Source

pub fn delete_many(&mut self, ids: &[i32]) -> Result<usize>

Deletes several tasks in one statement; unknown ids are simply not counted, and an empty slice is a no-op.

let mut tasks = Tasks::new()?;
let ids_to_delete = vec![101, 102, 103];
let deleted_count = tasks.delete_many(&ids_to_delete)?;
println!("Deleted {} tasks", deleted_count);
Source

pub fn exists(&mut self, id: i32) -> Result<bool>

True when a task with this id exists.

let mut tasks = Tasks::new()?;
let task_id = 1;
if tasks.exists(task_id)? {
    println!("Task exists and can be updated");
} else {
    println!("Task not found");
}
Source

pub fn update(&mut self, task: &Task) -> Result<()>

Updates name, comment and completeness; identity fields and tag links stay as they are. Errors when the task has no id or no longer exists.

let mut tasks = Tasks::new()?;
let task_id = 1;
let mut task = tasks.get_by_id(task_id)?.unwrap();
task.name = "Updated task name".to_string();
task.completeness = Some(75);
tasks.update(&task)?;
Source

pub fn get_by_id(&mut self, id: i32) -> Result<Option<Task>>

Fetches one task by id, tags included.

let mut tasks = Tasks::new()?;
if let Some(task) = tasks.get_by_id(42)? {
    println!("Found task: {}", task.name);
} else {
    println!("Task with ID 42 not found");
}

Trait Implementations§

Source§

impl Debug for Tasks

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Tasks

§

impl !RefUnwindSafe for Tasks

§

impl !Sync for Tasks

§

impl !UnwindSafe for Tasks

§

impl Send for Tasks

§

impl Unpin for Tasks

§

impl UnsafeUnpin for Tasks

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more