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
db.query(r#" REMOVE TABLE dog; REMOVE TABLE person; DEFINE TABLE dog SCHEMAFULL; DEFINE FIELD name ON TABLE dog TYPE string; DEFINE FIELD age ON TABLE dog TYPE int; DEFINE TABLE person SCHEMAFULL; DEFINE FIELD name ON TABLE person TYPE string; DEFINE FIELD fname ON TABLE person TYPE string; DEFINE FIELD dog ON TABLE person TYPE record(dog); "#,).await?;let dog = Dog{name:"rex".into(),age:3,};let created_dog_id:Vec<CreatedId> = db.create("dog").content(dog).await?;let created_dog_id:Thing = created_dog_id.first().expect("No created dog").id.clone();let person = Person{name:"name".into(),fname:"first name".into(),dog: created_dog_id,};let _:Vec<CreatedId> = db.create("person").content(person).await?;
Select Person with linked Dog:
letmut person_with_dog_response:Response = db
.query("SELECT {name:name, fname:fname, dog:dog} AS a_person, dog.* AS a_dog FROM person")// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^.await?;let person_with_dog:Vec<PersonWithDog> =
person_with_dog_response.take::<Vec<PersonWithDog>>(0)?;dbg!(&person_with_dog);
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
-
For the exemple:
Person
----record-link---->Dog
.Creations:
Select
Person
with linkedDog
:Output:
What is the idiomatic/nicer way to do this ?
Beta Was this translation helpful? Give feedback.
All reactions