Fork me on GitHub
#datomic
<
2017-11-12
>
zignd00:11:04

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?

marshall00:11:31

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

marshall00:11:21

If you're using client api ^^

zignd01:11:11

@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?

val_waeselynck08:11:43

@zignd you may also want to check out Datomock (https://github.com/vvvvalvalval/datomock). I'm the author, feel free to ask me questions

zignd13:11:24

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

marshall01:11:35

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

marshall01:11:08

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

marshall01:11:27

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

zignd01:11:10

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

Desmond05:11:31

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?

val_waeselynck08:11:07

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

souenzzo14:11:15

(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}

zignd19:11:10

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?

zignd19:11:13

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

favila19:11:42

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

zignd19:11:47

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)
      (:tempids)
      (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

zignd19:11:43

Thanks @favila I'll check it out!