Replies: 1 comment
-
I solved this by using #[derive(sqlx::FromRow, Debug)]
struct User {
age: i16,
name: String,
}
// …
let users: Vec<User> = sqlx::query_as(
"SELECT age, name FROM users")
.fetch_all(&pool)
.await;
let users_df: DataFrame = struct_to_dataframe!(users, [age, name]).unwrap(); This way, I am still able to use dot notation to access the attributes, and the type information is available so the compiler is happy. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have this macro which converts a struct result from a
query!()
into a Polars DataFrame:This works great for queries run with
query!
. However, a query run withsqlx::query
returns a set ofPgRow
objects which return different types for each column. And when I adapt the relevant line:I get this error:
So, can I still use this approach to convert the result of a normal
sqlx::query()
call to a Polars DataFrame?Beta Was this translation helpful? Give feedback.
All reactions