Skip to content

Conversation

@bhavaygoel
Copy link

@bhavaygoel bhavaygoel commented Jun 27, 2024

i assumed the dummy table as:

{
    id SERIAL PRIMARY KEY,
    name VARCHAR(100),
    age INT
}

@@ -1,2 +1,3 @@
/target
/result
.env No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every file needs to end with a line break.

Suggested change
.env
.env

select_all_users().await?;

Ok(())
} No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Suggested change
}
}


#[tokio::main]
async fn main() {
if let Err(e) = db::run_db_operations().await {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Abstract that out to a variable; conciseness is good but this harms readability.

use std::env;

pub async fn insert_user(name: &str, age: i32) -> Result<(), Error> {
dotenv().ok();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't explored this yet but there's probably a better place for this? I can't imagine doing this in every single function.


pub async fn insert_user(name: &str, age: i32) -> Result<(), Error> {
dotenv().ok();
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too, probably should be attached to some global/pseudo-global context that is available readily.

@GetPsyched GetPsyched marked this pull request as draft June 27, 2024 19:26
@GetPsyched GetPsyched mentioned this pull request Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants