Fork me on GitHub
#datomic
<
2019-05-16
>
hadils01:05:52

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).

donaldball02:05:37

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"]}]

hadils04:05:44

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…

donaldball13:05:00

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

lilactown14:05:02

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

favila15:05:00

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

favila15:05:51

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

lilactown15:05:13

gotcha. thanks all!

conan16:05:18

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

hadils16:05:40

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
                    coll
                    :customer/url customer-url
                    :customer/funding-sources)]]
    (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)

hadils17:05:18

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?

ghadi18:05:01

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

favila18:05:06

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

hadils18:05:01

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?

ghadi18:05:40

you cannot create empty entities on the right hand side

ghadi18:05:51

whether card-many or card-one

hadils18:05:57

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.

steveb8n01:05:58

this is awesome