Fork me on GitHub
#datomic
<
2016-05-25
>
rauh08:05:51

Is there a list of how database function parameters get converted?

rauh08:05:00

For instance, a clojure set gets quietly converted to a java.util.HashSet. Which was very confusing and broke my function. This is also not documented anywhere. I posted this on the mailing list a few days ago, but it hasn't been published.

Ben Kamphaus13:05:56

@rauh: at present Java collections — java.util.HashSet, java.util.ArrayList, etc. — not documented at present because it falls out of an implementation details. We’re considering whether or not to change the behavior in a future release and will document the boundaries when we make that decision.

Ben Kamphaus13:05:11

definitely understand why it’s surprising at present.

jannis17:05:27

Hi. There may be an obvious question but how do I query only the datoms that were introduced/modified/removed in a specific transaction? I know I can run (let [db (d/db conn)] (d/q ... (d/history db) (d/t->tx (d/basis-t db)))) but then I can't use pull in the query because that doesn't work against the history.

Ben Kamphaus17:05:23

@jannis: you want to do a query against the log, as with the last few examples on this page: http://docs.datomic.com/log.html

Ben Kamphaus17:05:56

is X in the db? - (d/db conn) was X ever in the db? - (d/history db) was X in the db at this time? (as-of filter) did X get added after this point? (since filter) what data was in X transaction (log)

jannis17:05:04

@bkamphaus: Nice summary of scenarios, thanks 🙂

jannis17:05:18

However, I'm testing against an im-memory db, which doesn't have a log.

jannis17:05:46

I guess since would work if there is a simple way to obtain the penultimate transaction.

jannis17:05:03

Something like d/next-t just with previous instead of next.

zane21:05:35

When testing queries that use the pull syntax I'm assuming I need to create a memory-backed Datomic connection and transact some test fixtures into it?

zane21:05:16

(Or use d/with.)

bvulpes21:05:17

zane: 'tis what i do

bvulpes21:05:33

i don't think d/with will work, as those datasets aren't "proper datomic databases"

Ben Kamphaus21:05:23

not sure I follow what is meant by “those datasets”, d/with returns db-after, db-before etc. and these are database values.

harold21:05:46

For protecting tests that mutate state from each other's damage we also enjoy: https://github.com/vvvvalvalval/datomock (bonus: our tests run a zillion times faster because we only migrate the test database once at the start of the test runs)

bvulpes22:05:27

(let [test-str (str gensym)] (d/create-database test-str) (d/connect test-str)) ?

bvulpes22:05:46

(d/transact schema/schema.clj (d/connect test-str))

bvulpes22:05:23

and if you don't want to do that for each test you can always create-database and delete-database in the test ns fixtures

bvulpes22:05:44

which is vastly slower but whatever at least you don't have to worry about cross-test state persistence

bvulpes22:05:05

bkamphaus: i must've misunderstood how d/with works.

zane22:05:32

@bvulpes: Something like this:

(defn empty-db-with-schema []
  (d/create-database uri)
  (let [conn (d/connect uri)
        db (d/db conn)]
    (d/delete-database uri)
    (d/release conn)
    (-> db
        (d/with schema)
        :db-after)))

zane22:05:55

If all your tests need to do is query you could call that once and use the returned database value in all of your tests.

zane22:05:20

If you need to test code that calls d/transact it's another story.

bvulpes22:05:29

my tests are pretty side-effecty, so i tend to test code that transacts pretty frequently.

zane22:05:12

Seems like vvvvalvalval/datomock just automates use of d/with.

bvulpes23:05:50

#railslifestyle

bvulpes23:05:01

there's a pragmatic middle ground.