This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-12
Channels
- # adventofcode (2)
- # aleph (2)
- # announcements (5)
- # aws (5)
- # babashka (25)
- # beginners (167)
- # calva (8)
- # cider (1)
- # clj-kondo (3)
- # cljsrn (19)
- # clojure (87)
- # clojure-conj (7)
- # clojure-dev (19)
- # clojure-europe (1)
- # clojure-italy (14)
- # clojure-losangeles (1)
- # clojure-nl (4)
- # clojure-norway (3)
- # clojure-spec (18)
- # clojure-uk (29)
- # clojuredesign-podcast (3)
- # clojurescript (40)
- # clojurex (11)
- # core-async (13)
- # core-logic (2)
- # cursive (16)
- # data-science (4)
- # datascript (10)
- # datomic (53)
- # emacs (1)
- # events (15)
- # fulcro (71)
- # jobs (1)
- # jvm (2)
- # malli (4)
- # nrepl (2)
- # pathom (74)
- # re-frame (1)
- # reitit (19)
- # remote-jobs (1)
- # rewrite-clj (18)
- # ring (2)
- # shadow-cljs (132)
- # spacemacs (22)
- # tools-deps (65)
there is no entity in the Client API, maybe you're using that?
kind of depends what you're trying to do
are you using on-prem or cloud?
yeah so, clearly I'm a noob here. I'm trying to get up to speed on datomic cloud. I've managed to create a schema that creates users with first name, last name, user name, email address, and some settings. I'm trying to query for all the settings of a specific user, but what I get back looks like it's the entity id.
So I was trying to get that setting based on the entity id. But perhaps I'm way off in trying to do that
I was running this query and hoping to get back the actual settings for a user -
(d/q '[:find ?settings
:where [?user :user/username ?username]
[?user :user/settings ?settings]]
db "myusername")
instead I get back [[79] [80]]
yes, the entity api is only available for peers in Datomic On-prem, so that won't be available. I would recommend looking at the Pull API instead https://docs.datomic.com/cloud/query/query-pull.html
that will let you pull back the data for the selected users in the shape you want
Ok thanks. I'm curious when one should use pull instead of query. Is pull just more commonly used for retrieving multiple nested values?
querying will primarily give you back tuples - if that's good, then use that. if you instead wanted more map-like nested data, then use pull
and of course you can use them together! which is kind of shown on that page
I noticed that arguments of db fns in our peer server are Java types, where i'd have expected clojure datastructures. Is this deliberate?
Example? You mean like ArrayList instead of Vector when returning from an aggregating query?
but if the query is running using peer api, your inputs are in-process. nothing is getting coerced
It’s in regards of a transaction function. So i transact a db/fn into the peer (i think?) which accepts an argument.
When i use the client api to invoke that function in a transaction, and check the type of the argument it’s the java equivalent. so a java.util.Arrays$ArrayList
for example.
Yes, i figured that was the reason. I’m just curious whether this is considered a bug or is deliberate
It caused some confusion on our staging env because our dev-setup uses https://github.com/ComputeSoftware/datomic-client-memdb, which doesn’t have the same side effect
Not sure how deliberate it is, but the defaults for fressian are very lazy about preserving types exactly
Hmmm, will keep it in mind then. Is there any way to get the types so that they’ll work properly with clj or should i encode the data myself in that case?
you should be careful with only relying on what's documented in the apis and not necessarily expect any particular concrete types. Java types are used because Datomic apis can be used from other jvm langs (Java, Groovy, etc)
Is this valid data for a Datomic Cloud transaction function to return?
[[:db/add 56246616830509142 :tags :untrusted]
[:db/add 56246616830509142 :tags :verified]
[:db/retract 56246616830509142 :tags :unknown]]
{:db/ident :tags
:db/valueType :db.type/keyword
:db/cardinality :db.cardinality/many
:db.attr/preds 'valid-tag?}
ok, so the types are valid; now it depends on whether the valid-tag?
predicate returns true
I'm very confident that part is working properly as I've plugged things in to test it. The problem I'm now having is:
(let [tx [(list* 'update-tags-tx hash hash-type tags)]]
tx (d/transact
conn
{:tx-data tx}))
is returning count not supported on this type: Keyword
. Any ideas?Just to be thorough:
(def valid-tags #{:trusted :untrusted :unknown :accepted :verified :unauthorized :malicious})
(defn valid-tag? [tags]
(every? valid-tags [tags]))
One thing I'm noticing is that the tx
variable is wrapping the output of update-tags-tx
in brackets however the update-tags-tx is returning a [ [...] [...] [...]]
already so we're seemingly triply wrapping that which is odd to me but if I don't do that then d/transact
yells at me and says it must be a list of a map
This is my transaction function which when I test it at the repl it works totally fine but perhaps there is some count
going on in here that I'm missing?
(defn update-tags-tx
"Transaction function which when given a map of hashes and a set of tags, will find the
entity who has those hashes and will update that entity's tags"
[db hash hash-type new-tags]
(let [eid (ffirst
(d/q
'[:find ?e
:in $ ?hash ?hash-type
:where
[?e ?hash-type ?hash]]
db
hash
hash-type))
current-tags (set (:tags (d/pull db '[:tags] eid)))
tags-to-add (clojure.set/difference new-tags current-tags)
tags-to-retract (clojure.set/difference current-tags new-tags)
tx (mapv (fn [addition] [:db/add eid :tags addition]) tags-to-add)
retractions (mapv (fn [retract] [:db/retract eid :tags retract]) tags-to-retract)
tx (reduce
(fn [state retraction]
(conj state retraction))
tx
retractions)]
tx))
Anyway I don’t see a count in there. Does the ex-info data on the exception give clues as to what stage is failing, tx or ensure?
tags
referring to the valid-tags? function? I noticed that name was wrong too tag
would be what I want.
I chose (list* ...)
based on https://github.com/Datomic/ion-starter/blob/master/src/datomic/ion/starter.clj#L172 because no variation of https://docs.datomic.com/cloud/transactions/transaction-functions.html#calling worked without errors