You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm wanting to put what should be a small json blob that defines a dataset schema into my database. The issue is when I do this I get the following error.
expected struct `sqlx::types::Json`, found enum `JsonValue`
#[derive(sqlx::FromRow,Serialize,Deserialize,Debug,Clone)]pubstructDataset{#[serde(rename = "datasetId")]pubdataset_id:Uuid,#[serde(rename = "name")]pubdataset_name:String,#[serde(rename = "schema")]pubdataset_schema:Json<DatasetSchema>,#[serde(rename = "createdAt")]pubcreated_at:DateTime<Utc>}pubasyncfnget_dataset(ctx:&sqlx::PgPool,dataset_id:Uuid) -> Result<Option<Dataset>,sqlx::Error>{let dataset = sqlx::query_as!(Dataset,r#"SELECT dataset_id, dataset_name, dataset_schema as "dataset_schema!: sqlx::types::Json<DatasetSchema>", created_at FROM datasets WHERE dataset_id = $1"#, dataset_id).fetch_optional(ctx).await?;returnOk(dataset);}
Is there a way to coerce the value without having to write out every field in the struct? Since it requires a literal I can't even simplify the code with concat! which means using the json fields adds an annoying amount of query complexity.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm wanting to put what should be a small json blob that defines a dataset schema into my database. The issue is when I do this I get the following error.
Failing Code
Working Code
Is there a way to coerce the value without having to write out every field in the struct? Since it requires a literal I can't even simplify the code with concat! which means using the json fields adds an annoying amount of query complexity.
Beta Was this translation helpful? Give feedback.
All reactions