edgedb / edgedb-rust

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

Still expecting implicit id #228

Closed Pepeye closed 1 year ago

Pepeye commented 1 year ago

Describe the bug Still expecting implicit id when querying and returning typed nested shapes from edgedb and using the edgedb_derive crate.

Reproduction Below is the rust code and example schema

use dotenv::dotenv;
use edgedb_derive::Queryable;
use edgedb_protocol::model::Uuid;
use edgedb_tokio::create_client;
use eyre::Result;
// use serde::{Deserialize, Serialize};

#[derive(Debug, Queryable)]
pub struct Person {
    // pub id: Uuid,
    pub username: String,
    pub email: String,
    pub name: Name,
    // pub ts: Ts,
}

#[derive(Debug, Queryable)]
pub struct Name {
    pub firstname: String,
    pub lastname: String,
}

#[derive(Debug, Queryable)]
pub struct Ts {
    pub created: String,
    pub updated: String,
}

#[tokio::main]
async fn main() -> Result<()> {
    dotenv().ok();

    let query = r#"
        select Person {
            username,
            email,
            name: { firstname, lastname },
        } filter .username = 'spidey' limit 1
    "#;

    let pool = create_client().await?;
    let v: Person = pool.query_required_single(query, &()).await?;
    println!("{:#?}", v);
    Ok(())
}
module default {
  type Person {
    required link name -> Name;
    required property username -> str;
    required property email -> str {
      constraint exclusive;
    };
    required link ts -> Ts;
    index on (.email)
  }

  type Name {
    required property firstname -> str;
    required property lastname -> str;
  }

  type Ts {
    required property created -> cal::local_datetime {
      default := cal::to_local_datetime(datetime_current(), 'UTC');
    }

    required property updated -> cal::local_datetime {
      default := cal::to_local_datetime(datetime_current(), 'UTC');
    }
  }
}

Expected behavior Struct / shape to be printed in terminal but instead getting compiler showing an expected implicit id error as evidenced in the screenshots below.

Screenshot 2023-03-29 at 22 44 17

If I run the query without the id and expect a shape without ids i get this error. If i add an id to the query and the struct the error disappears. However it seems even with nested ids this also doesn’t work (e.g. having id in each of the nested struct and query so that each nested edgedb type returns an id).

Versions (please complete the following information):

Additional context This relates to #175 which is showing as fixed, merged.

tailhook commented 1 year ago

Works for me. Although, it's not in any released version.

I'm going to release soon. Feel free to reopen if you see this issue in edgedb-tokio 0.4.0 or git version.

Dhghomon commented 1 year ago

I had this bug the entire time too but upon moving to 0.4 it's gone. 🎉