Fork me on GitHub
#datomic
<
2018-08-07
>
Oliver George05:08:29

What's a good way to reset the database to a known state for integration testing for an Ions app? Thinking it through I could use (do (delete-database...) (create-database ...) (transact fixtures ...)). I wondered if there was something like a (clone-database ...) or (reset-db-to tx-id) which might simplify restoring to a known state. Clearly this is somewhat at odds with providing an immutable db.

steveb8n09:08:36

I use the datomock lib. it makes a big difference in speed when integration testing. only works with peer/mem db. it’s one option that works for me

Oliver George10:08:20

Yeah. Something like that for cloud would be useful.

steveb8n00:08:16

I found a way to have both. You can proxy the client conn/db and use mem underneath. then you can use datomock with client/cloud code.

steveb8n00:08:38

I created a gist for this and there’s an early lib out there as well

orestis05:08:24

I’ve been discussing Datomic with my CTO and his biggest fear is Cognitect being a relatively small company combined with the closed source nature of Datomic. Is there any documentation that tries to address this kind of fear? Is there way to get the data out in a usable form? Can we sign a source code access agreement?

orestis05:08:36

This is more specific to Datomic cloud, I guess.

Alex Miller (Clojure team)11:08:51

Datomic sales would be the best people to talk to about all that <mailto:[email protected]|[email protected]>

okocim15:08:29

In some of the examples on Github, I see that the client and connections are memoized as such:

(def get-client
  (memoize #(d/client 
             {:server-type :ion
              :region "us-east-1"
              :system "stu-8"
              :query-group "stu-8"
              :endpoint ""
              :proxy-port 8182})))
(def get-http-client (memoize #(http/create {})))
(def db-name "ion-event-example")
(def get-conn (memoize #(d/connect (get-client) {:db-name db-name})))
Is memoizing the call to d/client ok to do in general, or is this just something that was done for development purposes? Likewise, would one want to memoize the call to d/connect?

marshall16:08:45

“Datomic connections do not adhere to an acquire/use/release pattern. They are thread-safe and long lived. Connections are cached such that calling datomic.api/connect multiple times with the same database value will return the same connection object.”

curtosis19:08:32

I find myself building up a lot of tx maps with (merge m (when x {:attr-x x}) (when y {:attr-y y})) … this must be a common datomic pattern? how do y’all normally handle that idiomatically?

curtosis19:08:55

I guess that’s not datomic-specific, but it comes up a lot in building txes.

Alex Miller (Clojure team)19:08:34

cond-> is your friend

4
okocim19:08:34

@curtosis I find myself using this pattern quite a bit as well. I personally prefer using:

(cond-> {}
  x (assoc :attr-x x)
  y (assoc :attr-y y))
over merge, but it seems like it’s essentially the same. I’ve also created some macros in the past to expand this for me, if I’m able to extract a common pattern

curtosis19:08:16

lol @okocim I had in the back of my head that it looked a little cond->ish

Alex Miller (Clojure team)19:08:18

cond-> both reads better and is faster so definitely preferred

curtosis19:08:35

ok, now a definitely datomic-related question… I’m using the “best practice” asyc tx-pipeline and sometimes I’ll get no actual elements transacted, even though the batch looks fine.

curtosis19:08:12

ordinarily I’d asssume they were already-asserted items, but I don’t see them in the datomic console

curtosis19:08:29

what should I be looking for to troubleshoot?

csm22:08:34

in on-prem, can you call a transaction function from within a transaction function? My use case was to extend a transaction function :foo/bar with a :foo/bar2, which took the results from the original :foo/bar, but added more to it

marshall22:08:44

Yes, you can @csm