Fork me on GitHub

There's a talk by Rich in which he talks about a Datomic feature he calls "with" that allows you to simulate changes in a database without actually changing it. But I couldn't find any documentation on it, does anyone knows a name, a keyword or a link that could help me find it?


Same api structure as transact. Use the db after value from it to examine the speculative db value


If you're using client api ^^


@marshall Nice! May I ask you another question? I'm executing unit tests against a temporary in memory instance of Datomic. I guess it would be better to do so using with instead right? There's a recommend practice between these two options?


@zignd you may also want to check out Datomock ( I'm the author, feel free to ask me questions


Interesting project @U06GS6P1N, I gave you a star. I'm still learning Clojure and Datomic, but I will keep it in mind, I might end up needing it during my unit tests


Probably depends on your specific goal. The logical structure should be similar if not the same


The advantage of with is if you need a non trivial basis db for the test you can use one backed by persistent storagr


I.e. you can have a restored backup of prod loaded in your test system and use with against that


Thanks for the insight @marshall . I guess another advantage for me would be not having to load the schema every time I create an in memory instance


Java interop question: I would like to take the results of a query and construct a java object with them. Rather than doing (MyObj. (first result) (second result)) I would like to use apply to pass the arguments to the constructor of MyObj. However when I try to do that I get a compiler error. I'm guessing that just means that the . constructor is not actually a function. Is there a clean way to do this?


@U7Y912XB8 I guess you need to wrap the constructor in a multi-arity fn (which you can generate using a macro)


(defrecord Foo [a b])
=> user.Foo
(defn into-Foo [[a b]] (new Foo a b))
=> #'user/into-Foo
(into-Foo [1 2])
=> #user.Foo{:a 1, :b 2}
;;By default there is this macros:
(->Foo 1 2)
=> #user.Foo{:a 1, :b 2}
(map->Foo {:a 1 :b 2})
=> #user.Foo{:a 1, :b 2}


How do I properly provide a temporary id to a transaction so that I can take it out of the :tempids of the returned map?


I tried to create a temporary id with (d/tempid :db.part/user) and then use it in the transaction data but the returned map still returns a negative long for the temporary id instead of the value I created through d/tempid


Use d/resolve-tempid. It does the tempid to negative number conversion for you.


Here an example demonstrating what I'm trying to accomplish:

(let [content "test"
      author-id 1
      tid (d/tempid :db.part/user)
      tx-data [{:db/id           tid
                :tweet/content   content
                :tweet/author-id author-id}]]
  (-> @(d/transact conn tx-data)
      (get tid))) ; it doesn't work because the map associated with `:tempids` contains a negative long as a key to the real id I'm trying to retrieve


Thanks @favila I'll check it out!