This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-03-20
Channels
- # announcements (5)
- # aws (15)
- # babashka (12)
- # beginners (87)
- # calva (13)
- # cider (16)
- # clj-kondo (4)
- # clojure (22)
- # clojure-argentina (1)
- # clojure-europe (9)
- # clojure-houston (1)
- # clojure-nl (2)
- # clojure-norway (25)
- # clojure-uk (5)
- # clojurescript (12)
- # core-typed (37)
- # cursive (15)
- # datomic (40)
- # editors (8)
- # emacs (4)
- # events (1)
- # hyperfiddle (29)
- # keechma (8)
- # leiningen (6)
- # lsp (7)
- # malli (25)
- # off-topic (26)
- # pathom (10)
- # portal (3)
- # re-frame (22)
- # reitit (1)
- # releases (1)
- # ring (2)
- # shadow-cljs (18)
- # yamlscript (1)
Hello,
(defn example [db xx-uuid] (:db/id (d/entity db [:example/uuid xx-uuid])))
;=> 17592186456789
This function returns the db/id
of the entity based on its UUID. However, I'm looking for a simpler way to directly retrieve the value of the attribute without needing to obtain the db/id
first. (xx-uuid is the value given by me but extracted from outsource, want to be sure is it really in the db)
Is there a more straightforward way to achieve this in Datomic? Any insights or suggestions would be greatly appreciated. (Without using standart queries)I want to retrieve the value associated with the :unique/attr
attribute related to the entity identified by the returned entity ID.
(xx-uuid is the value given by me but extracted from outsource, want to be sure is it really in the db) as I mentioned in my main question 🙂
I don’t think I follow. If the value is in the db, you get an entity id (or an entity in d/entity case). if it is not, you don’t. that’s how you know
it would be helpful if you rearticulate what you have (input), and what you're trying to know (output)
I'm getting the expected value from the api response, which is xxx
. I'm using this xxx
value as a parameter for a query to check if the expected transaction is completed. I want to match the actual value (`actualxxx`) with the expected value (`expectedxxx`). I can achieve this with standard queries, but I'm looking for the simplest way to accomplish this.
I don’t see the connection between this and the original question. Could you maybe show us what you are doing now more precisely? And we could suggest refactors which preserve its behavior.
I see then I am wrong at somewhere, thanks all. deleting the question to clear mess here.
(defn example [db uuid] (get (d/entity db [:example/uuid uuid]) :example/uuid) ) ;=> #uuid "3d32a2be-f9b0-4cd5-b8a6-10dcbd970439" This is the what I wanted, found it. Thanks for everyone, just wanted to leave here.
Could be rewritten as
(defn example [db uuid]
(when (d/entid db [:example/uuid uuid])
uuid))
This is what I meant by > If the value is in the db, you get an entity id (or an entity in d/entity case). if it is not, you don’t. that’s how you know
literally if the [:example/uuid uuid]
lookup found something, you know its value for :example/uuid
is uuid
Yes, I understand. I'm planning to use it for deftest unit tests, and my company prefers to assert with direct values to check them instead of relying on whether something is not nil, a count, or any other conditions. Therefore, I'm seeking the simplest way to write assertions directly against the database for this purpose.
In the https://docs.datomic.com/pro/schema/schema.html?search=%20#composite-tuples, there does not appear to be any discussion of cardinality-many attributes.
Is it valid for such an attribute to be among the tupleAttrs
? If so, is it valid for tupleAttrs
to contain a mix of cardinality-many and cardinality-one attrs?
I would imagine that the cardinality of the composite tuple attr itself would also need to be many, and than the tuple would have one value for each unique combination of tupleAttrs
. But I can’t tell from the docs if this will actually work.
> A tuple is a collection of 2-8 scalar values card many constituents are not allowed
I’m trying to make a query against three different attributes faster by making an indexed tuple. It works really well in the cardinality-one case.
I have a bunch of queries like this:
'[:find ?group (count ?story)
:in $ [?group ...]
:where
[?story :story/group ?group]
[?story :story/workflow-state ?wf]
[?wf :workflow-state/type :workflow-state.type/started]
[(clubhouse.txfns.util/missing-or-false? $ ?story :story/archived?)]]
These get slower than I need them to be if the cardinality of stories in a group is very high.
If I store the combo of :story/group
, :story/workflow-state
, and :story/archived?
in an indexed composite tuple, this is about an order of magnitude faster:
'[:find ?group (count ?story)
:in $ [?group ...] [?started-state ...]
:where
[(tuple ?group ?started-state nil) ?archived-nil-tuple]
[(tuple ?group ?started-state false) ?archived-false-tuple]
(or-join [?story ?archived-nil-tuple ?archived-false-tuple]
[?story :story/group+wf-state+archived ?archived-nil-tuple]
[?story :story/group+wf-state+archived ?archived-false-tuple])]
(a little messiness here to handle both false
and nil
values for archived)
:story/group
is cardinality-one and this works great. But I was hoping to extend this pattern to other similar “container” attrs like :story/labels
which are cardinality-many. But clearly that is not an option.Followup question: since you cannot stop maintaining a composite tuple attribute once it exists, does this mean that any cardinality-one attribute which is a component of a composite tuple attribute can never have its cardinality changed to many?
You should just try it to see what you can and can’t do, but IME you cannot rename attributes which are referenced by component tuples (i.e. using ident resolution tricks to make it read a different attribute); if you cannot even rename, I doubt you could change cardinality, since that seems a prerequisite.