This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-17
Channels
- # announcements (1)
- # babashka (21)
- # beginners (46)
- # calva (21)
- # cherry (10)
- # cider (5)
- # clojure (54)
- # clojure-europe (16)
- # clojure-nl (2)
- # clojure-norway (37)
- # clojure-spec (7)
- # clojure-uk (4)
- # clojurescript (30)
- # conjure (3)
- # cursive (1)
- # datalog (5)
- # datascript (3)
- # datomic (13)
- # emacs (5)
- # fulcro (82)
- # girouette (1)
- # helix (4)
- # hyperfiddle (2)
- # joyride (1)
- # juxt (1)
- # kaocha (4)
- # lambdaisland (3)
- # luminus (1)
- # malli (15)
- # off-topic (60)
- # pathom (3)
- # polylith (1)
- # practicalli (3)
- # releases (1)
- # ring (4)
- # sql (3)
- # squint (85)
I'm curious, do folks find it more useful to create functions that perform queries or to create variables that hold queries. For example do you prefer
(defn find-by-email [db email]
(d/q '[:find ?e
:in $ ?email
:where [?e :email ?email]]
db
email))
or
(def find-by-email '[:find ?e
:in $ ?email
:where [?e :email ?email]])
The first, by far, since the query depends on the email parameter. Sticking the query in a var and then using it elsewhere will make the dependency on the var less obvious.
If you are to use the query in var format, consider to use the map format - its mich easier to do introspection. I have used that map to add extra parameters (sorting etc)
Thanks for the feedback! Makes sense to me. If anyone has a counter argument I’d still love to hear it!
I’ve got one for you. I frequently compose queries using pull expressions. those pull expressions can be def’d since they don’t have any dependencies
Ah interesting, I could see that being useful. By pull expressions do you mean something like this?
(def everything '[*])
(d/q '[:find (pull ?u pattern)
:in $ pattern
:where [?u :user/email _]]
db
everything)
I try to use :in values for :where clauses only but that’s just a personal preference
https://clojuredocs.org/clojure.template/apply-template sorry it’s Fri-eve here, I should not drink and slack
I’ve noticed that the official API docs (https://docs.datomic.com/client-api/datomic.client.api.html#var-db) on d/db
say that there is ILookup access to a key named :db-name
. That is nil for me in Cloud and dev (memory) databases. I see a :database-id
in production databases, and an :id
in memory ones. Not sure where the best place to report that is, so I’m saying it here in hopes someone on the core team will pick it up. I’m doing caching of things based on which database something comes from, so having a key I can safely derive from the db that isn’t the db itself is important and useful. For now I’ve been using the :database-id
, but that worries me since it is an undocumented key.