Project Address: https://github.com/MrTwoc/todo-rs
The previous chapter implemented a tabular output of tasks, but the beautification effect was not very good.
This time, the JSON file that stores tasks has been changed to use SQLite for data storage, and the task levels have been changed from a fixed number of levels to u8 levels, allowing for a larger hierarchical space.
Additionally, a user management feature based on SQLite has been added to prepare for a potential future change of the project structure to a client-server architecture.
A TOML configuration file has been added, currently containing only one parameter: if_login. If set to false, it skips login, with the default being local login.
If support for PostgreSQL is to be added later, the connection address can be set in the configuration file.
Current challenges encountered:
- Batch status updates for tasks in SQLite
- Task editing in SQLite
For task editing, it directly uses a match statement to match parameters during iteration, updating each one individually. Each matching case is replaced with a single line:
conn.execute(
"UPDATE tasks SET description = ? WHERE id = ?",
(value, task_id),
)?;
For batch updates of tasks, the IDs are grouped into an array using iter and collect, then the status is modified for each task during iteration:
pub fn sql_update_status(args: &[&str]) -> Result<(), Box<dyn std::error::Error>> {
let status = args[1];
let ids: Vec<u32> = args[2..]
.iter()
.map(|s| s.parse())
.collect::<Result<_, _>>()?;
let conn = get_conn()?;
for id in ids {
conn.execute(
"UPDATE tasks SET task_status = ? WHERE id = ?",
(status, id),
)?;
}
info!("[sqlite] Task status updated successfully");
println!("Task updated");
Ok(())
}
Unimplemented content:
Integrate sorting algorithms
Integrate searching algorithms
Hide the application to run in the system tray
Change task deletion to a status change for tasks; deleted tasks will have their status changed from 0 to 1, rather than being directly deleted.