Conversation
This will be separate from the main binary as that will house the GUI in the future. `todo` will be just the CLI to interface with tasks.
GetPsyched
left a comment
There was a problem hiding this comment.
All of the interaction with the client should be done as methods implemented on Task. So, all the respective code should be moved from src/bin/todo/*.rs to src/lib.rs.
Also, please run just lint and just clippy before committing to avoid more back and forth.
src/db/mod.rs
Outdated
|
|
||
| pub async fn get_client() -> Result<&'static Client, Error> { | ||
| CLIENT.get_or_try_init(init_client).await | ||
| } No newline at end of file |
There was a problem hiding this comment.
whole crud operation in the lib.rs? or just the db operation?
src/db/mod.rs
Outdated
| use tokio_postgres::{Client, NoTls, Error}; | ||
| use dotenv::dotenv; | ||
| use std::env; | ||
| use tokio::sync::OnceCell as TokOnceCell; |
There was a problem hiding this comment.
It was just in the docs, can use just as it is tho.
| impl ToSql for Priority { | ||
| fn to_sql( | ||
| &self, | ||
| _ty: &Type, | ||
| out: &mut BytesMut, | ||
| ) -> Result<IsNull, Box<dyn StdError + Send + Sync>> { | ||
| match self { | ||
| Priority::Low => out.extend_from_slice(b"low"), | ||
| Priority::Medium => out.extend_from_slice(b"medium"), | ||
| Priority::High => out.extend_from_slice(b"high"), | ||
| } | ||
| Ok(IsNull::No) | ||
| } | ||
|
|
||
| fn accepts(ty: &Type) -> bool { | ||
| ty.name() == "priority" | ||
| } | ||
|
|
||
| tokio_postgres::types::to_sql_checked!(); | ||
| } | ||
|
|
||
| impl FromStr for Priority { | ||
| type Err = String; | ||
|
|
||
| fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| match s.to_lowercase().as_str() { | ||
| "low" => Ok(Priority::Low), | ||
| "medium" => Ok(Priority::Medium), | ||
| "high" => Ok(Priority::High), | ||
| _ => Err(format!("Invalid priority: {}", s)), | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Can this be avoided? Given that now there is a Display trait for Priority now
There was a problem hiding this comment.
It was an error because of the custom type "enum" in database, which was not recognized by tokio as it needed to convert string to enum type and enum type to string, read from the cli.
There was a problem hiding this comment.
if it's resolved this way, great. but i had to implement the same for Difficulty as well
There was a problem hiding this comment.
Is the Display trait not enough?
There was a problem hiding this comment.
I dont think so, because after the Display trait was implemented, i still got the error in the tokio while reading the enum value of difficulty
| new_deadline: NaiveDateTime, | ||
| } | ||
|
|
||
| pub async fn command(_args: &Args) { |
There was a problem hiding this comment.
The underscore in _args specifies that it's an unused variable. If we're using it, remove the underscore.
src/bin/todo/update.rs
Outdated
| #[clap(long)] | ||
| new_priority: Priority, | ||
| #[clap(long, value_parser=mindmap::parse_datetime)] | ||
| new_deadline: NaiveDateTime, |
There was a problem hiding this comment.
Let's keep the deadline as NaiveDate; in hindsight, I don't see the time being useful for this since that's too much micro-management
|
Moved to #8 |
No description provided.