Fork me on GitHub
#datomic
<
2015-09-08
>
caskolkm09:09:50

is there a simple way to flat a nested vector with transaction data?

[[[:db.fn/retractEntity 17592186045471]]
[[[:db.fn/retractEntity 17592186045470]
  {:db/id {:part :db.part/user, :idx -1001126},
   :field/ref 17592186045462,
   :city/name “Fooo",
   :fieldset/_values 17592186045469}]]]
clojure.core/flatten does not solve it

jthomson10:09:56

@caskolkm: does it need to flatten to an arbitrary depth or can you just use concat and vec?

caskolkm10:09:08

@jthomson:

[
[:db.fn/retractEntity 17592186045471]
[:db.fn/retractEntity 17592186045470]
{:db/id {:part :db.part/user, :idx -1001126},
   :field/ref 17592186045462,
   :city/name “Fooo",
   :fieldset/_values 17592186045469}
]
should be the result 😉

jthomson10:09:40

not sure why you have those outer vectors, valid tx data is a sequence containing either vectors or maps (`[[:db/add ..] {:db/id ..}]`). If you can do without those then (apply concat tx-datas) will combine them for you.

caskolkm10:09:35

those outer vectors come from mapv on nested attributes

caskolkm10:09:53

to decide what we need to edit, delete or add 😉

jthomson10:09:48

well if there is guaranteed to be just one child in each outer vec then you can just (mapcat first tx-datas)

jthomson10:09:17

otherwise you'll need to concat them twice.

caskolkm10:09:09

Thnx @jthomson for the help! simple_smile

caskolkm10:09:18

got a solution simple_smile

bensu13:09:13

@clojuregeek: I used to use lein-datomic but after a while I decided it was not worth the overhead and started using shell scripts.

clojuregeek14:09:19

@bensu: thanks, yeah it doesn't seem to add alot of functionality that you couldn't add in other ways. Thanks for your input simple_smile

bostonaholic18:09:12

just like to share a win I had today using datomic. I had dates across multiple entities that were saved incorrectly. Essentially the year was saved as 12 instead of 2012. So when writing a script to update all of those entities, I used the power of datomic to query the schema to find all date attributes, then filter those bad dates:

(d/q '[:find ?e (pull ?attr [:db/ident]) ?date
       :where
       [?attr :db/valueType :db.type/instant]
       [?tx :db/ident :db/txInstant]
       [(not= ?tx ?attr)]
       [?e ?attr ?date]
       [(.getYear ^java.util.Date ?date) ?year]
       [(< ?year 100)]]
     (d/db conn))
Super powerful

bostonaholic18:09:56

would have not been nearly as easy if we were just using a traditional rdbms

potetm18:09:54

@bostonaholic: noice! I liiiiike.