Rust newbie here.
Using tokio_postgres, I want to dynamically process database query results by iterating over rows and then iterating over each field in a row.
I'm expecting I should be able to do something like this:
let rows = client.query("select * from category", &[]).await?;
if rows.len() > 0 {
let columns = rows[0].columns();
for row in &rows {
for col in columns {
match row.get(col.name()) { // <-- Error: "type annotations needed"
// What do I do here?
}
}
}
}
But, as indicated, the compiler has a problem with me wanting to match on the result of the get
function.
One option I have considered is to call get
with a different type annotation, depending on the type inferred from the column, but not sure if this is a good option. In the end, the value itself will probably have to go into an Enum that can cater for all the database types.
What I ultimately want to do, is expose a function to Rhai that can call a SELECT query, then process the results dynamically. But I am stuck on how I would handle the values of different types.
Perhaps I have gone too far down a path and need to backtrack to see things in context.