Rust how to convert vector of raw string into the Json or convert complete vector into something which suits the project

I have queried the database using PgRow and then storing it into the string

let rows = sqlx::query("SELECT name FROM categories")
.await.expect("Unable to");

for row in rows{
    let name: String=row.get("name");
    println!("name is ⭐: {}",name)

Then I'm adding the string to the vector

Now I'm unable to send the vector to the front send please check the code from github and help me out

It would be very helpful if you could add the error message you receive and the code where it occurs to your question. Also a hint on the behaviour your program exhibits versus the behaviour you expect could be beneficial to us so we can help you better.

I assume you mean this endpoint?

Here you are not trying to send JSON to the frontend but try to embed a Vec<String> into a handlebars template.

Now this looks wrong to me:

    let mut vector=Vec::new();


First, you forgot to actually call selecting here. Also, I assume you want to, pass Vec<String> to your template. What you are constructing here (once you call selecting) would be Vec<Result<Vec<String>, ()>>. Try this instead:

-    let mut vector=Vec::new();

-    vector.push(selecting.to_owned());

// don't panic your endpoint in production 
// (pass a proper error to the client instead), 
// but for testing its fine.
+    let vector = selecting().unwrap(); 

and pass that to your template.

I hope this will help. Without error message I'm limited to guesswork here.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.