Skip to main content

Tags

Struct Tags 

Source
pub struct Tags { /* private fields */ }
Expand description

Tag table access, including task-tag links.

Implementations§

Source§

impl Tags

Source

pub fn new() -> Result<Self>

Opens the database and ensures both tag tables exist (migration v3 creates them officially).

use kasl::db::tags::Tags;

let mut tags = Tags::new()?;
Source

pub fn create(&mut self, tag: &Tag) -> Result<i32>

Inserts the tag and returns its assigned id; duplicate names are rejected by the unique constraint.

use kasl::db::tags::{Tags, Tag};

let mut tags = Tags::new()?;
let tag = Tag::new("priority".to_string(), Some("orange".to_string()));
let tag_id = tags.create(&tag)?;
println!("Created tag with ID: {}", tag_id);
Source

pub fn update(&mut self, tag: &Tag) -> Result<()>

Updates name and color by id; errors when the tag has no id or no longer exists.

let mut tags = Tags::new()?;
let tag_id = 1;
let mut tag = tags.get_by_id(tag_id)?.unwrap();
tag.name = "high-priority".to_string();
tag.color = Some("crimson".to_string());
tags.update(&tag)?;
Source

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

Deletes the tag; its task links go with it via CASCADE.

let mut tags = Tags::new()?;
let tag_id = 1;
tags.delete(tag_id)?;
Source

pub fn get_all(&mut self) -> Result<Vec<Tag>>

Returns every tag, sorted by name.

let mut tags = Tags::new()?;
let all_tags = tags.get_all()?;
for tag in all_tags {
    println!("Tag: {} ({})", tag.name, tag.color.unwrap_or("no color".to_string()));
}
Source

pub fn get_by_name(&mut self, name: &str) -> Result<Option<Tag>>

Fetches one tag by exact (case-sensitive) name.

let mut tags = Tags::new()?;
if let Some(tag) = tags.get_by_name("urgent")? {
    println!("Found tag: {} with color: {:?}", tag.name, tag.color);
} else {
    println!("Tag 'urgent' not found");
}
Source

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

Fetches one tag by id.

let mut tags = Tags::new()?;
if let Some(tag) = tags.get_by_id(42)? {
    println!("Tag ID 42: {}", tag.name);
}
Source

pub fn get_tags_by_task(&mut self, task_id: i32) -> Result<Vec<Tag>>

Returns the task’s tags, sorted by name; empty when it has none.

let mut tags = Tags::new()?;
let task_id = 1;
let task_tags = tags.get_tags_by_task(task_id)?;
for tag in task_tags {
    println!("Task has tag: {}", tag.name);
}
Source

pub fn get_tasks_by_tag(&mut self, tag_id: i32) -> Result<Vec<i32>>

Returns the ids of tasks carrying the tag.

let mut tags = Tags::new()?;
let tag_id = 1;
let task_ids = tags.get_tasks_by_tag(tag_id)?;
println!("Tag is used by {} tasks", task_ids.len());
Source

pub fn add_tag_to_task(&mut self, task_id: i32, tag_id: i32) -> Result<()>

Links a tag to a task; idempotent thanks to OR IGNORE.

let mut tags = Tags::new()?;
let (task_id, tag_id) = (1, 1);
tags.add_tag_to_task(task_id, tag_id)?;
Source

pub fn remove_tag_from_task(&mut self, task_id: i32, tag_id: i32) -> Result<()>

Unlinks a tag from a task; a missing link is not an error.

let mut tags = Tags::new()?;
let (task_id, tag_id) = (1, 1);
tags.remove_tag_from_task(task_id, tag_id)?;
Source

pub fn remove_all_tags_from_task(&mut self, task_id: i32) -> Result<usize>

Removes every tag link from the task; returns how many went.

let mut tags = Tags::new()?;
let task_id = 1;
let removed_count = tags.remove_all_tags_from_task(task_id)?;
println!("Removed {} tag associations", removed_count);
Source

pub fn set_task_tags(&mut self, task_id: i32, tag_ids: &[i32]) -> Result<()>

Replaces the task’s tag set: clears existing links, then adds the given ids. Not transactional - a failure after the clear leaves the task untagged. Ids must exist; use Tags::get_or_create_tags when unsure.

let mut tags = Tags::new()?;
let task_id = 1;

let new_tag_ids = vec![1, 3, 5]; // urgent, backend, review
tags.set_task_tags(task_id, &new_tag_ids)?;

let current_tags = tags.get_tags_by_task(task_id)?;
assert_eq!(current_tags.len(), 3);
Source

pub fn get_or_create_tags(&mut self, names: &[String]) -> Result<Vec<i32>>

Resolves names to tag ids, creating missing tags with a color from the default rotation.

let mut tags = Tags::new()?;
let tag_names = vec!["urgent".to_string(), "backend".to_string()];
let tag_ids = tags.get_or_create_tags(&tag_names)?;

Auto Trait Implementations§

§

impl !Freeze for Tags

§

impl !RefUnwindSafe for Tags

§

impl !Sync for Tags

§

impl !UnwindSafe for Tags

§

impl Send for Tags

§

impl Unpin for Tags

§

impl UnsafeUnpin for Tags

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