Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: db.rs for inserting and querying profiles #4

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

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
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(())
}
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.

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.

2 participants