0

I'm working on a web app in Rust. I'm using Tokio Postgres, Rocket and Tera (this may be relevant).

I'm using the following to connect to my DB which doesn't fail in either case.

 (sql_cli, connection) = match tokio_postgres::connect("postgresql://postgres:*my_password*@localhost:8127/*AppName*", NoTls).await{
        Ok((sql_cli, connection)) => (sql_cli, connection),
        Err(e) => return Err(Redirect::to(uri!(error_display(MyError::new("Failed to make SQLClient").details)))),
    };

My query is as follows. I keep my queries in a separate file (I'm self taught and find that easier).

let query= sql_cli.query(mycharactersquery::get_characters(user_id).as_str(), &[]).await.unwrap();

The get characters is as follows. It takes a user ID and should return the characters that they have made in the past.

pub fn get_characters(user_id: i16) -> String {
    format!("SELECT * FROM player_characters WHERE user_id = {} ORDER BY char_id ASC;", user_id)
}

In my main file, I have one GET which is /mycharacters/<user_id> which works. This GET returns an HTML file. I have another GET which is /<user_id> which returns a Tera template. The first works fine and loads the characters, the second doesn't: it just loads indefinitely. I initially thought this was to do my lack of familiarity with Tera.

After some troubleshooting, I put some printouts in my code, the one before and after the SQL call work in /mycharacters/<user_id>, but only the one before writes to the terminal in /<user_id>. This makes me think that Tera isn't the issue as it isn't making it past the SQL call.

I've found exactly where it is going wrong, but I don't know why as it isn't giving an error.

Could someone please let me know if there is something obvious that I am missing or provide some assistance?

P.S. The database only has 3 columns, so an actual timeout isn't the cause.

I expected both of these SQL calls to function as I am connected to my database properly and the call is copied from the working call.

  • Since you didn't provide a [mre] there is not much we can do to help. Rather than describing the code handling `GET /mycharacters/` and `GET /` you should show it to us. You can add it by [editing](https://stackoverflow.com/posts/75092695/edit) your question to include it. – cafce25 Jan 12 '23 at 08:38

0 Answers0