This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-27
Channels
- # announcements (1)
- # beginners (71)
- # braveandtrue (4)
- # cider (1)
- # cljs-dev (4)
- # cljsrn (8)
- # clojure (111)
- # clojure-italy (5)
- # clojure-spec (22)
- # clojure-uk (8)
- # clojurescript (80)
- # cryogen (14)
- # cursive (7)
- # data-science (1)
- # datomic (25)
- # dirac (1)
- # figwheel-main (4)
- # fulcro (13)
- # incanter (1)
- # off-topic (6)
- # other-languages (3)
- # pathom (11)
- # portkey (5)
- # re-frame (13)
- # reagent (3)
- # reitit (24)
- # ring-swagger (7)
- # shadow-cljs (63)
- # spacemacs (3)
- # specter (4)
- # tools-deps (9)
đź‘‹ Hi everyone, I'm trying to find some resources on normalizing nested data structures for designing/loading data into Datomic... I'm a little confused about how to represent ordered collections like PersistentArrayMap or vectors. Any pointers?
I'm currently thinking of batch loading (maybe with doseq
) one transaction at a time using time as a way to order the values, but that seems complected
Hi @loganpowell say attributes with many
cardinality don't maintain any concept of ordering. If you need this, you'd need provide additional attributes (`:next` refs for lists, :index
or something for arrays) to capture that in the db. There are a couple libs that address some of this that might be helpful directly or give you some ideas https://github.com/vvvvalvalval/datofu#implementing-ordered-to-many-relationships-with-an-array-data-structure, https://github.com/dwhjames/datomic-linklist
Thank you @eoliphant! I also saw this: https://github.com/pmbauer/datomizer I will definitely look into the libraries you've recommended!
I have an entity that contains a cardinality many attribute required-tags
, then I want to get all the tags in that array
now I’m doing two queries, one to get the array, and one that takes the array as input to get the tags themselves
Can you show an example of what you are doing? I don’t know the valuetype of required-tags or the structure of your entities, or precisely what you mean by the two queries
;; What the list of tags looks like
user=> (d/q '[:find ?t .;
:where [_ :file/required-tags ?t]]
@db)
["tag1" "tag2" "tag3" "tag4"]
;; What I wish would work
user=> (d/q '[:find ?e
:where [?e :tag/name ?t]
[_ :file/required-tags ?t]]
@db)
#{}
;; What does work, but uses two queries
user=> (d/q '[:find [(pull ?e [*]) ...]
:in $ [?names ...]
:where [?e :tag/name ?names]]
@db
(d/q '[:find ?t .
:where [_ :file/required-tags ?t]]
@db)))
[<a bunch of data>]
I do t see that there is any difference between what you wish works and what does work
You want entities with :tag/name values that are anywhere asserted as a :file/required-tags value?
in the second query, the :where
essentially translates to [?e :tag/name ["tag1" "tag2" "tag3" "tag4"]]
What I’m after is to “unnest” the array into something like
(or [?e :tag/name "tag1"]
[?e :tag/name "tag2"]
[?e :tag/name "tag3"]
[?e :tag/name "tag4"])
man. Cognitect really needs to partner with Salesforce. Everything that salesforce needs in order to accurately trend and analyze domain data is built into the core guarantees of datomic