Fork me on GitHub
#datomic
<
2018-03-15
>
donmullen11:03:32

Is it possible to pass a pull pattern that contains some :default settings to query? If so - what’s the correct format? I get an error:

(d/q '[ :find (pull ?j query)
        :in $ ?bin query
        :where
        [?j :job/bin ?bin]]
  db
  "1047470"
  '[ (:job/fully-paid :default false) ])

datomic.impl.Exceptions$IllegalArgumentExceptionInfo: :db.error/invalid-attr-spec Cannot interpret as an attribute spec: (:job/fully-paid :default false) of class: class clojure.lang.PersistentList

donmullen13:03:12

@marshall I’ve used get-else successfully in queries - but not :default in a pull pattern. Not sure what I’m missing. My example above seems to follow pattern in the docs :

[:artist/name (:artist/endYear :default "N/A")] 
and in the day-of-datomic example:
;; default option
(d/pull db '[:artist/name (:artist/endYear :default 0)] mccartney)

marshall13:03:43

ahh; don’t think you can pass the pull expr as a parameter

marshall13:03:49

if you’re using it in the find expression

marshall13:03:22

oh, yes you can

marshall13:03:26

hrm. one second 🙂

donmullen13:03:22

@marshall I also got that error using d/pull as well which I was thinking would surely work - hmmm…

marshall13:03:36

what version of datomic/

marshall13:03:41

or is this in cloud?

donmullen13:03:59

datomic-pro-0.9.5651

marshall13:03:41

that feature was released in 5656

marshall13:03:49

there is an older syntax for limit exprs, but the one you’re using there ^ is the newer one based on attr-with-options

marshall13:03:29

(d/q '[:find [(pull ?e pattern) ...]
       :in $ ?artist pattern
       :where [?e :release/artists ?artist]]
     db
     led-zeppelin
     '[(:release/name :as "Release")])

marshall13:03:43

^ that gives:

[{"Release" "Houses of the Holy"} {"Release" "Immigrant Song / Hey Hey What Can I Do"} {"Release" "Immigrant Song / Hey Hey What Can I Do"} {"Release" "Heartbreaker / Bring It On Home"} {"Release" "Led Zeppelin III"} {"Release" "Whole Lotta Love / Living Loving Maid"} {"Release" "Led Zeppelin III"} {"Release" "Led Zeppelin III"} {"Release" "Led Zeppelin"} {"Release" "Led Zeppelin IV"} {"Release" "Led Zeppelin"} {"Release" "Led Zeppelin IV"} {"Release" "Led Zeppelin"} {"Release" "Led Zeppelin II"} {"Release" "Led Zeppelin II"} {"Release" "Led Zeppelin II"} {"Release" "Led Zeppelin II"}]

marshall13:03:14

limit and default should work the same way