This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-20
Channels
- # announcements (5)
- # beginners (37)
- # calva (3)
- # cider (23)
- # clojure (98)
- # clojure-dev (16)
- # clojure-europe (5)
- # clojure-italy (4)
- # clojure-nl (5)
- # clojure-spec (7)
- # clojure-uk (52)
- # clojurescript (14)
- # cursive (15)
- # data-science (1)
- # datomic (20)
- # emacs (7)
- # flambo (2)
- # fulcro (10)
- # jackdaw (1)
- # jobs (3)
- # joker (2)
- # juxt (3)
- # keechma (3)
- # leiningen (8)
- # luminus (3)
- # music (1)
- # off-topic (83)
- # pathom (19)
- # re-frame (19)
- # reitit (4)
- # shadow-cljs (76)
- # spacemacs (95)
- # tools-deps (16)
How do I give a :db/id to an entity? I'm using :db/id when trying to transact my data and I get a "unable to resolve entity". How can I say "if it doesn't exist, make one with this id"?
Use a tempid (string) to create a new entity. Note that an entity is inherently it’s id, you don’t “give” it one.
Tell me if my instructions were incorrect. I have a blacklist entity and I want to add things to a cardinality-many attribute of it. I was told I would be able to use :db/id to "name" it for sake of argument :blacklist and from here on out when I want to add to that blacklist I would be able to include :db/id :blacklist in my map-form transaction. Is that a flawed assumption so far?
What’s really happening is that all data in datomic is assertions and retractions (datoms) which state one “fact”. They are structured like [entity-id, attribute-id, value, transaction, assertion-or-retraction]
the map form from a pull is a projection of this, where all assertions sharing the same entity-id
are joined together, the entity id itself is put on :db/id
, and the attributes+values are map entries
similarly, the map form of a transaction is syntactic sugar that expands out into [:db/add entity-id attribute value]
assertions
added to all this, you don’t have much control over the actual value of the entity id, so it doesn’t make much sense to talk about “naming” an entity
if you want a possibly new entity, you use a tempid: [:db/add "some-string-representing-a-tempid" attribute value]
or {:db/id "some-string-representing-a-tempid" attribute value}
So is the answer to the "I only want a single blacklist and only want to ever add stuff to that one" to, before any transactions, query for the eid of the blacklist and use that (or a temp-id on first go)?
you can use an upserting indexed attribute for this purpose: the index lookup will resolve to an existing entity id or create one if it doesn’t exist yet
https://docs.datomic.com/on-prem/identity.html discusses various ways of “addressing” an entity