Using rust and the actix framework, I am trying to fetch a list of records from postgres and return it as JSON.
I am referencing this example code: https://github.com/actix/examples/tree/master/databases/postgres
The following are my changes. The get_users
function returns only one user because of the pop
. How do I fix this to return the entire list of users so I can return it as JSON?
pub async fn get_users(client: &Client) -> Result<User, MyError> {
client
.query("SELECT * FROM testing.users", &[])
.await?
.iter()
.map(|row| User::from_row_ref(row).unwrap())
.collect::<Vec<User>>()
.pop()
.ok_or(MyError::NotFound)
}