This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-19
Channels
- # announcements (3)
- # asami (3)
- # babashka (39)
- # beginners (65)
- # calva (13)
- # cider (4)
- # clj-kondo (69)
- # cljdoc (19)
- # cljs-dev (2)
- # clojure (90)
- # clojure-dev (10)
- # clojure-europe (61)
- # clojure-france (15)
- # clojure-nl (8)
- # clojure-uk (2)
- # clojurescript (28)
- # conjure (2)
- # core-logic (4)
- # cursive (8)
- # datalevin (5)
- # datascript (7)
- # datomic (14)
- # depstar (4)
- # events (1)
- # graphql (7)
- # holy-lambda (5)
- # jobs (5)
- # kaocha (1)
- # malli (14)
- # membrane-term (13)
- # missionary (13)
- # nextjournal (6)
- # off-topic (1)
- # polylith (15)
- # portal (10)
- # re-frame (35)
- # reitit (1)
- # remote-jobs (3)
- # schema (3)
- # sci (121)
- # spacemacs (6)
- # tools-build (8)
- # tools-deps (74)
- # xtdb (7)
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
[?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]
(def order-from-line-item
'[:find ?order
:in $ ?line-item
:where
[?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]})
What is the most succinct way to assert a unique entity? I thought I can do something like
(d/transact
conn
{:tx-data
[{:db/id [:unique/id "bestid5"]}]})
the effect of the above is I think not what I want. When I pull
(d/pull
(d/db conn)
'[*]
[:unique/id "bestid5"])
=> #:db{:id nil}
Now I'm trying this to assert and reference the unique in the same tx
(d/transact
conn
{:tx-data
[{: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?Yep, you need a tempid
(d/transact
conn
{:tx-data
[{:airstats.pipeline/id "bestid4"
:db/id "tempid-for-bestid4"} ;a unqiue
{:airstats.job/pipeline ;ref to unique
"tempid-for-bestid4"}
{:airstats.pipeline/id "bestid5"
:db/id "tempid-for-bestid5"}
{:airstats.job/pipeline ;I'll have multiple of those
"tempid-for-bestid5"}]})
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
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.