Fork me on GitHub

Is there a way to do nested transactions, for example, i want to add several bank accounts for a customer and then put their :db/ids in the customer/accounts (cardinality many attribute).


I think you’d generally use temporary ids for this:

[{:db/id "a1" :account/name "A1"}
 {:db/id "a2" :account/name "A2"}
 {:customer/accounts ["a1 "a1"]}]


I was thinking that, but the issue is that I don't know the number of accounts in advance. I know how to craft this, but I was looking for a more elegant way…


Accumulate the accounts in a set alongside the txn you’re building and then conj the customer accounts op onto the txn?


when using q, does the db always need to be the last argument?

Lennart Buit14:05:03

I think it is whatever position you have $ at in your :in

Lennart Buit14:05:50

Or … looking through my own code, I appear to have it both as last and as first argument, which coincides with where the $ is in the :in


correct; if :in is not explicit, it's assumed to be [$] and you may supply a db as the only arg. If :in is explicit then arg order corresponds to whatever :in says, you can put db anywhere. $ must be the name of the magic implicit db though


Not sure if it's absolutely necessary, but at least strong convention dictates all db names should start with $ also


gotcha. thanks all!


With a peer-server, how can i make it reconnect after deleting and re-creating the database without killing the process?


I am having a problem with a Datomic Cloud transaction function. Here's the function:

(defn xact-coll
  "Transaction function that commits a collection, then puts the entities
  of the collection into attr"
  [db coll attr1 k attr2]
  (let [m (into [] (map-indexed #(assoc %2 :db/id (str %1)) coll))
        c (assoc {}
            attr1 k
            attr2 (into [] (map #(str %) (range (count coll)))))]
    (concat m [c])))
and here's the invocation:
(defn save-funding-sources [customer-url funding-source-coll]
  (let [coll (remove-nil-keywords funding-source-coll)
        tx-data ['(stackz.db/xact-coll
                    :customer/url customer-url
    (d/transact (schema/get-connection) {:tx-data tx-data})))
And here's the error message:
ExceptionInfo Don't know how to create ISeq from: clojure.lang.Symbol  clojure.core/ex-info (core.clj:4739)


I fixed this problem, now I'm getting

ExceptionInfo tempid used only as value in transaction  clojure.core/ex-info (core.clj:4739)
How do I refer to an entity id in the same transaction?


that error means you have a tempid on the right hand side somewhere, without any attributes on it


the problem here is you have an assertion like [:db/add 123 :attr "value"] without any other use of "value" in the "e" slot


If you look at the transaction function, I am using the tempids as values to a cardinality many attribute. Do I have to break it up into two separate transactions?


you cannot create empty entities on the right hand side


whether card-many or card-one


I thought that the :db/id values in the collection were on the left-hand side, then they would be on the right-hand side when I am putting them into :customer/funding-sources.


this is awesome