-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Hello! Discussions are not enabled, so I am making a ticket for this... apologies. :)
I am currently working on a SurrealDB Driver and I am currently "fighting" with related records.
Basically, SurrealDB has no JOIN, instead you use FETCH $field... in SELECT to pick fields whose related records should be resolved.
To demonstrate:
DEFINE TABLE book;
DEFINE FIELD author ON book TYPE record<author>;
DEFINE TABLE author;
DEFINE FIELD name ON author TYPE string;
When querying, a JSON object is returned (or a nested CBOR structure) as a result and currently, my driver's Next(dest []any) error method will see any sub-object as being a complex type and return []byte to avoid crashes.
For instance:
{
"ID": "book:eragon",
"author": {
"ID": "author:christoph",
"name": "Christoph Paolini"
}
}And basically, this would result in:
dest[0] = ID -> string
dest[1] = author -> []byte
...but after reading through the docs, I am not so sure if this should be the case or not. Hence, why I would like to ask some people with more experience in this :)
When using sqlx' ScanStruct methods (and similiar), how does it actually determine the keys to use to read into the struct? Is there any "post processing" I could possibly do to assist from within my driver?
So far, I see that perhaps I should instead use dot-notation for the columns: ID, author.ID, author.name. Is that assumption correct?
I just want to make sure my driver is well compatible. So far I tried to make REL work - and it kinda does but just fails when automatically attempting to determine foreign keys which just do not exist in SurrealDB - but I think there is still room for improvements.
Thank you very much and kind regards,
Ingwie