question about database design: I suspect this probably does not matter as much for XTDB, but in my app, I have different types of users. There are some common attributes between them (basically first/last name, email, and maybe contact number)... and then some other fields that are unique to each type of user. Would the fact that I am using XTDB favour using single table inheritance, concrete table inheritance (separate table - or I guess document - for each type of user)... or does it not matter?
you can still get a doc by id, but yes the iteration of all docs of a type might be a bad usecase
we used these single key/value maps as ids in a project, and at least it was good when inspecting the database, you always know what you are dealing with
it is a nice idea... what about using a prefix? so "<prefix>"-<rest of id>. Technically not a UUID, but u could have the <rest of id> portion be an actual uuid. This also of course assumes that there is a way to query using prefix when you're searching for "user type A", vs type B, etc.
We have used namespaced id's in XTDB v1, like
:xt/id {:user/id <uuid>}
:xt/id {:customer/id <uuid>}
v2? You can just insert all different types of users in the same users table, it doesn’t matter if they have different attributes
Sorry no, v1
in v1 there are no tables, so I don’t know how you can have “table inheritance”?
just documents
but the same applies, there is no requirement for all documents to have the same attributes
Gotcha. Thank you
This link should help explain STI: https://docs.gitlab.com/ee/development/database/single_table_inheritance.html
personally, I would mostly avoid ORMs and use a language with 1st class data
but the discussion of having some kind of “type” attribute for discrimnating between different types of docs is valid
yes. The question is not about ORMs, but about how folks would structure their documents
best is to not need an attribute just to specify a document’s “type”
you can do that by querying by some attribute that only occurs in that type, or you could even encode the type in the doc id in v1 (like {:sometype <uuid>} map as the xt id
hmm. I’ve not considered that, but that’s an interesting idea. Right now my ids are UUIDs.
I’ve been wondering about the utility of using UUIDs, and having to do a parse-uuid (give the string representation) step just to do a query
sorry, maybe I misunderstood. Are you saying to use a map as the xt id?
iirc, you can even query all docs of a “type” by doing range {:sometype <0000-…>} - {:sometype <ffff-...>}` query
yes, use the whole map as the id
on the topic of identifiers, have you looked at something like snowflake ids (not necessarily the implementation as done by twitter; more info https://en.m.wikipedia.org/wiki/Snowflake_ID) as opposed to UUIDs?
haven’t, but UUIDv7 looks nice as well
thank you for that note! re that range query, would you be able to give me an example of how to do that query?
sorry, I don’t have an example handy, but just using the <= and >= in datalog will give you range queries
no worries. I’m aware of the predicate functions; just not sure about how to query when the value in question is “nested”, instead of a “direct” EAV value
hey @jf.slack-clojurians be aware predicates over nested data won't benefit from indexing, you will essentially end up with table scans - but you can do it like:
[?e :att ?some-map]
[(get ?some-map :some-key) ?val]
[(<= ?val 100)]
you can similarly use get-in, it's just calling clojure.core/* fns
thank you for that note. In that case, I think i'll refrain from using maps