I am using Axum and sqlx to build an api endpoint that takes a table name and returns all the data in the table in the form of json. The number of columns and their types are not known beforehand. What would be the best way to go about this.
I did write the following code:
let query = format!("SELECT * FROM {}", table);
let result = sqlx::query(&query).fetch_all(&db).await.unwrap();
for row in result.iter() {
for col in row.columns() {
let value = row.try_get(col.name()).unwrap();
}
}
Of course value needs a type, I tried using an enum and a Vector of that enum to store the values but couldnt get it right. Any nudging towards the right direction would be appreciated.