Specifying relationships in schemas and casting when using SDKs #206
freakyfelt
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey y'all, I'm trying to play around with SurrealDB and hitting a snag in terms of modelling an author for a post. In traditional SQL this would be a reference field, however I'm not sure how I would define such a field on SurrealQL (not sure what the TYPE would be).
Perhaps something like this, but that shows an error.
LET $personTable = (DEFINE TABLE person SCHEMAFULL); DEFINE TABLE post SCHEMAFULL; DEFINE FIELD author TYPE $personTable;
Or should I be purely doing a RELATION here? The problem I foresee is when one wants a single
person
to be an actor (e.g. 'created' should always be a singleperson
), but I'm not seeing SurrealQL allowing for constraints on relations either 🤔The other snag for this (ignoring the schema fun) is around using
CREATE $tb CONTENT $data
from at least the JS SDK (but I suspect all of them) in that one cannot use JSON to readily insert anything more than primitives + objects. So, for example, if I want to create apost
with acreatedBy
I have to drop into raw SurrealQL. Understandable that serialising non-primitive symbols while not introducing SQL injection attacks isn't a walk in the park, however this combined with the above seem a bit difficult. Perhaps a third argument that allows one to apply castings to different fields? e.g.Beta Was this translation helpful? Give feedback.
All reactions