Hi!
I want convert the result of sqlx::query! to JSON.
My ideals are as follows. This one doesn't work.
let examples = sqlx::query!(
"SELECT id, name FROM example",
)
.fetch_all(&**pool)
.await?;
let json = serde_json::to_string(&examples);
alternative means
#[derive(sqlx::FromRow, serde::Serialize)]
struct Example {
id: i32,
name: String,
}
let examples = sqlx::query_as::<_, Example>(
"SELECT id, name FROM example",
)
.fetch_all(&**pool)
.await?;
let json = serde_json::to_string(&examples);
Do you have any other good ideas?
Thank you!
Hi!
I want convert the result of
sqlx::query!to JSON.My ideals are as follows. This one doesn't work.
alternative means
Do you have any other good ideas?
Thank you!