2

There is an example in SurrealDB documentation about using Rust's structs to store received data:

#[derive(Debug, Serialize)]
struct Name<'a> {
    first: &'a str,
    last: &'a str,
}

#[derive(Debug, Serialize)]
struct Person<'a> {
    title: &'a str,
    name: Name<'a>,
    marketing: bool,
}

I couldn't find an example about storing a Record in a struct. Should I use Thing or create a struct called Record with id field?

For example this is the database schema I use and I want to store the select result of a notification table as a struct:

Schema.surql:

DEFINE TABLE notification SCHEMAFULL;

DEFINE FIELD content ON notification TYPE string;
DEFINE FIELD user_id ON notification TYPE record(user);

Notification Struct:

#[derive(Debug, Serialize)]
struct Notification {
    content: String,
    user_id: TYPE_HERE, <= ???
}

What is the type to store record linkage in Rust?

Thanks!

eminfedar
  • 558
  • 3
  • 16

1 Answers1

-1

According to DEFINE FIELD docs and Record IDs

https://surrealdb.com/docs/surrealql/statements/define/field

https://surrealdb.com/docs/surrealql/datamodel/ids

I think you are supposed to put the type of the Record id for user table.

PXP9
  • 358
  • 1
  • 8
  • Yes, I know I need to use Record type in SurrealDB. I'm asking about usage of the Record type in Rust. Can you give a Rust Struct example? – eminfedar Jul 21 '23 at 15:53