pub struct TodoRepository { /* private fields */ }Expand description
SQLite repository for session todo state.
Implementations§
Source§impl TodoRepository
impl TodoRepository
Sourcepub fn new(path: &Path) -> Result<Self, TodoError>
pub fn new(path: &Path) -> Result<Self, TodoError>
Open or create a todo database at the given path.
§Errors
Returns an error when the database file cannot be opened.
Sourcepub fn init_schema(&self) -> Result<(), TodoError>
pub fn init_schema(&self) -> Result<(), TodoError>
Sourcepub fn create(&self, input: CreateTodo) -> Result<TodoItem, TodoError>
pub fn create(&self, input: CreateTodo) -> Result<TodoItem, TodoError>
Create a todo item, or return an existing item with the same title in the same session (idempotent create).
§Errors
Returns an error when the item cannot be persisted or looked up.
Sourcepub fn create_batch(
&self,
inputs: Vec<CreateTodo>,
) -> Result<Vec<TodoItem>, TodoError>
pub fn create_batch( &self, inputs: Vec<CreateTodo>, ) -> Result<Vec<TodoItem>, TodoError>
Create multiple todo items idempotently in one call.
Each item follows the same idempotency rule as [create]: if an item
with the same title already exists in the session, the existing item is
returned unchanged. Items within the same batch that share a title also
deduplicate to the first occurrence.
§Errors
Returns an error when any item cannot be persisted or looked up.
Sourcepub fn list(
&self,
session_id: Uuid,
query: TodoQuery,
) -> Result<Vec<TodoItem>, TodoError>
pub fn list( &self, session_id: Uuid, query: TodoQuery, ) -> Result<Vec<TodoItem>, TodoError>
List todo items for a session.
§Errors
Returns an error when SQLite fails or stored metadata cannot be parsed.
Sourcepub fn update(
&self,
session_id: Uuid,
id: Uuid,
update: TodoUpdate,
) -> Result<TodoItem, TodoError>
pub fn update( &self, session_id: Uuid, id: Uuid, update: TodoUpdate, ) -> Result<TodoItem, TodoError>
Update mutable todo fields.
§Errors
Returns TodoError::NotFound when the item does not exist in the session.
Sourcepub fn update_status(
&self,
session_id: Uuid,
id: Uuid,
status: TodoStatus,
) -> Result<TodoItem, TodoError>
pub fn update_status( &self, session_id: Uuid, id: Uuid, status: TodoStatus, ) -> Result<TodoItem, TodoError>
Update item status and maintain completed_at.
§Errors
Returns TodoError::NotFound when the item does not exist in the session.
Sourcepub fn delete(&mut self, session_id: Uuid, id: Uuid) -> Result<bool, TodoError>
pub fn delete(&mut self, session_id: Uuid, id: Uuid) -> Result<bool, TodoError>
Delete an item and any dependency edges that reference it.
§Errors
Returns an error when SQLite fails.
Sourcepub fn add_dependency(
&self,
session_id: Uuid,
parent_id: Uuid,
child_id: Uuid,
) -> Result<TodoDependency, TodoError>
pub fn add_dependency( &self, session_id: Uuid, parent_id: Uuid, child_id: Uuid, ) -> Result<TodoDependency, TodoError>
Add a dependency edge after validating item existence and acyclicity.
§Errors
Returns TodoError::DependencyCycle if adding the edge would create a cycle.