This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-12
Channels
- # beginners (34)
- # boot (14)
- # cider (2)
- # cljs-dev (21)
- # cljsrn (1)
- # clojure (31)
- # clojure-android (10)
- # clojure-spec (12)
- # clojure-uk (3)
- # clojurescript (64)
- # cursive (31)
- # data-science (9)
- # datomic (27)
- # fulcro (11)
- # graphql (14)
- # jobs (1)
- # leiningen (1)
- # lumo (27)
- # off-topic (65)
- # om (2)
- # onyx (77)
- # pedestal (1)
- # re-frame (4)
- # shadow-cljs (6)
- # vim (1)
- # yada (3)
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
http://blog.datomic.com/2017/01/the-ten-rules-of-schema-growth.html @misha not sure if that's what you're looking for ?
@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 (https://github.com/vvvvalvalval/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}
have a look at https://clojuredocs.org/clojure.core/memfn
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
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