Derive Macro edgedb_tokio::Queryable

source ·
#[derive(Queryable)]
{
    // Attributes available to this derive:
    #[edgedb]
}
Expand description

Derive macro that allows structs and enums to be populated by database queries.

This derive can be used on structures with named fields (which correspond to “shapes” in EdgeDB). Note that field order matters, so the struct below corresponds to an EdgeDB User query with first_name followed by age. A DescriptorMismatch will be returned if the fields in the Rust struct are not in the same order as those in the query shape.

#[derive(edgedb_derive::Queryable)]
struct User {
    first_name: String,
    age: i32,
}

Field attributes

JSON

The #[edgedb(json)] attribute decodes a field using serde_json instead of the EdgeDB binary protocol. This is useful if some data is stored in the database as JSON, but you need to process it. The underlying type must implement serde::Deserialize.


#[derive(edgedb_derive::Queryable)]
struct User {
    #[edgedb(json)]
    user_notes: HashMap<String, String>,
}

Container attributes

JSON

The #[edgedb(json)] attribute can be used to unpack the structure from the returned JSON. The underlying type must implement serde::Deserialize.

#[derive(edgedb_derive::Queryable, serde::Deserialize)]
#[edgedb(json)]
struct JsonData {
    field1: String,
    field2: u32,
}