SurrealDB's CBOR usage drives me nuts; help me fix this code? #617
Replies: 1 comment 1 reply
-
In general with fxamacker/cbor, you can interpret unmarshalling and unmarshalling by implementing Maybe you can implement Something like this: func (p *MyOtherType) UnmarshalCBOR(data []byte) error {
// Decode raw data to models.RecordID.
// Fetch other data, etc.
// Populate MyOtherType struct fields.
}
I understand. I hope my comments are helpful despite being very general. 🙏 I'm not familiar with some of the internal data types in your code snippet and my current schedule doesn't allow me to dive into code bases unrelated to work (e.g. several projects/teams at work need my time and I haven't taken end-of-2024 break yet). |
Beta Was this translation helpful? Give feedback.
-
Hello!
Thanks to SurrealDB, I got very close up and intimate with CBOR in the form of a million issues in terms of building my structs and debugging stuff - because they use a lot of custom tags. Not too surprising since the spec leaves many unreserved slots - but this makes actually "making" things incredibly difficult...
Basically, when querying a row that references other tables, they will use
models.RecordID
as the return type. I tried to overwrite this with... well, this abomination:as you can tell, it's horrible. All I want to do is:
models.RecordID
(/s, multiples in an array)Ideally, I would love to write something like
When unmarshalling,
OtherTable
would contain amodels.RecordID
- however, I want to intercept that, and specifically that, and instead construct my own struct in it's place.Is that possible? Fetching nested data would be rather annoying otherwise...
Thank you and kind regards!
PS.: That's been like 4h of my day today... im so exhausted lol.
Edit: for context, here is SurrealDB's configuration with their custom tags https://github.com/surrealdb/surrealdb.go/blob/main/pkg/models/cbor.go
Beta Was this translation helpful? Give feedback.
All reactions