This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-06-28
Channels
- # adventofcode (12)
- # announcements (1)
- # asami (18)
- # aws (1)
- # babashka (20)
- # beginners (80)
- # calva (11)
- # cider (10)
- # circleci (5)
- # cljsrn (2)
- # clojure (37)
- # clojure-australia (15)
- # clojure-europe (32)
- # clojure-nl (2)
- # clojure-uk (26)
- # clojured (7)
- # clojurescript (10)
- # clojurewerkz (3)
- # cursive (45)
- # data-science (12)
- # datomic (3)
- # emacs (8)
- # events (3)
- # fulcro (23)
- # graphql (5)
- # helix (3)
- # jobs (1)
- # jobs-discuss (1)
- # juxt (3)
- # lsp (12)
- # malli (4)
- # meander (4)
- # reagent (11)
- # releases (1)
- # shadow-cljs (28)
- # sql (35)
- # tools-deps (9)
- # xtdb (25)
Hi, I’m trying different approaches to modelling my entities in Crux. If you have an “id-attribute” per entity type, for example :person/id
, :car/id
and :house/id
, is it sensible to then use the same value (some uuid) for :crux.db/id
. So it would look like this:
{:crux.db/id 0022-1111
:person/id 0022-1111}
{:crux.db/id 0033-1111
:house/id 0033-1111}
{:crux.db/id 0044-1111
:car/id 0044-1111}
Assuming those are either UUIDs or otherwise guaranteed not to clash between types, looks good to me 🙂
No, there are no uniqueness constraints on attribute values other than :crux db/id
You could build a tx fn to enforce uniqueness of attribute values on ingest, if you really needed. You would have to query those entities with q, there are no idents or lookup refs.
Crux separates constraints and schema from the data, this is by design.
If you can, try to leverage :crux.db/id. You're not limited to longs. I use it for URIs
They certainly can, many URIs have path segments that do just that.
That’s an interesting alternative to the approach I’m contemplating now: using the same “id-value” twice on each entity. Once on :crux.db/id
and once on a type-specific id such as user/id
However, I prefer to separate identity from type. Can you be certain that an entity won't ever change type (or, more likely, that you may need to rename a type as you refine your doman language)
I have an attribute that specifies the type, when I want an explicit type. Also, that works for situations where I want multiple types.
If I need to query all instances of a type, I query on that attribute
And :entity/type #{:user :vip}
Does your code check whether something is of a specific type before performing certain actions? Maybe I’m thinking about this the wrong way, but I guess type and identity are still pretty complected in my head… 😉
Yes, sometimes I use the type in multimethods to determine behaviour.
Mostly, my actions are simple puts into the db. Sometimes removes
You can even write Datalog query rules that work on types. So you can have a rule that can do type inference. For example, if all employees are users, and users can change their passwords, and Jack is an employee, then Jack can change his password.
YMMV of course, but I have found it that separating identity from type (the who from the what) delivers a lot of flexibility
I have an attribute that specifies the type, when I want an explicit type. Also, that works for situations where I want multiple types.
I wonder if the "type" vs. "identity" discussion is a worthy addition to this mini-doc? https://opencrux.com/community/faq.html#_modeling_types