edgedb / edgedb-rust

The official Rust binding for EdgeDB
https://edgedb.com
Apache License 2.0
208 stars 26 forks source link

Add note about using splats syntax #264

Closed hongquan closed 1 year ago

hongquan commented 1 year ago

EdgDB v3 introduced splats. However, Rust client user should be careful with it, because the output field order is arbitrary and the conversion of query_single result to your struct will fail.

It means, if you have:

#[derive(Debug, edgedb_derive::Queryable)]
pub struct BlogPost {
    pub id: Uuid,
    pub title: String,
    pub slug: String,
}

this code will sometimes fail:

let posts: Vec<BlogPost> = client.query("select BlogPost {*}", &()).await?;

when EdgeDB returns data as BlogPost {id, slug, title}.

Dhghomon commented 1 year ago

Very true. I have some notes on field order in my PR here and will add a note about splats too now that 3.0 is out.

https://github.com/edgedb/edgedb-rust/pull/236

Though a splat will work if deserializing into json with that attribute so in the meantime there is that option.