-
Hi, I have use diesel::sql_types::Json;
#[derive(Queryable)]
pub struct GMapsLocation {
pub id: i32,
pub place_id: String,
pub data: Json,
} And trying to do this: let results: Vec<GMapsLocation> = gmaps_locations
.select((id, place_id, data))
.load(&connection)
.expect("Erorr loading locations"); And then I get this:
No idea what is happening and I can't find an example of how to query Json anywhere in the docs. This also shows how to insert data: https://docs.diesel.rs/diesel/pg/types/sql_types/struct.Jsonb.html |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Inserts are working with this setup though as per the example on the Jsonb page. |
Beta Was this translation helpful? Give feedback.
-
OK. I found out what the issue was. Just like the input value from the documentation is a Also, we don't get the struct back that's in models but a vector of tuples instead. (Why have a model?) So the working code is: let results = gmaps_locations
.select((id, place_id, data))
.load::<(i32, String, serde_json::Value)>(&connection)
.expect("Erorr loading locations"); |
Beta Was this translation helpful? Give feedback.
OK. I found out what the issue was.
Just like the input value from the documentation is a
serde_json::Value
, the return value from the query is also aserde_json::Value
. I have no clue whatdiesel::sql_types::Json
is for then.Also, we don't get the struct back that's in models but a vector of tuples instead. (Why have a model?)
So the working code is: