Fork me on GitHub

Is there a idiomatic way for generating tmpids? gensym or randomUUID come to mind - whatever I realized for my use case I already have a unique string at hand


For us it depends on the use case. Generally the tempids are crafted by hand, and we use lookup refs for collections (I.e dynamic stuff). Gensym otherwise. UUIDs can be a good tool too especially if you have an unique-identity field for them either way

catjam 1

[?order :shop/line-items ??]

;; How do I get the order back when I have a line item?

;; I want to do what it says here

;; like this but I have cardinality/many

[?release :release/artists ?artist]

Joe Lane15:11:16


(def order-from-line-item
 '[:find ?order
   :in $ ?line-item
   [?order :shop/line-items ?line-item]])

(def the-db (d/db the-conn))
(def line-item-id "abc123")
(d/q {:query order-from-line-item :args [the-db line-item-id]})

👍 1
catjam 1

What is the most succinct way to assert a unique entity? I thought I can do something like

    [{:db/id [:unique/id "bestid5"]}]})
the effect of the above is I think not what I want. When I pull
   (d/db conn)
   [:unique/id "bestid5"])
=> #:db{:id nil}

Joe Lane17:11:37

You're close, (d/transact conn {:tx-data [{:unique/id "bestid5"}]})

👀 1
🎉 1

Now I'm trying this to assert and reference the unique in the same tx

  [{:airstats.pipeline/id "bestid4"}    ;a unqiue
   {:airstats.job/pipeline              ;ref to unique
    [:airstats.pipeline/id "bestid4"]}
   {:airstats.job/pipeline              ;I'll have multiple of those
    [:airstats.pipeline/id "bestid4"]}]})
"Unable to resolve entity: [:airstats.pipeline/id \"bestid4\"] in datom [-9223301668109598094 :airstats.job/pipeline [:airstats.pipeline/id \"bestid4\"]]",
Do I need to put a tmpid?

Joe Lane17:11:22

Yep, you need a tempid

  [{:airstats.pipeline/id "bestid4"
    :db/id "tempid-for-bestid4"}    ;a unqiue
   {:airstats.job/pipeline              ;ref to unique
   {:airstats.pipeline/id "bestid5"
    :db/id "tempid-for-bestid5"}
   {:airstats.job/pipeline              ;I'll have multiple of those
I'm not sure how your :airstats.job/pipeline relates to :airstats.pipeline/id but the above will create two different "airstats.job"s, each job references one "airstats.pipeline"


:airstats.job/pipeline is supposed to be a ref to an entity with :airstats.pipeline/id and multiple jobs can ref 1 pipeline. Thanks will check. Maybe I should rethink the schema and have jobs as a reference component on the pipeline entity

Joe Lane17:11:10

My only generic advice for you is to try and avoid thinking in rectangles if you can. Datomic doesn't operate in structs of entities. Instead, like Clojure, it operates as sets of attributes.

partywombat 1
Joe Lane17:11:48

(TBC, I'm not saying what you were asking about was necessarily bad or particularly rectangular)


haha I'll meditate on that!

👍 1

Could duplicate :where clauses impact query performance in any way?