cldwalker / datomico

Use datomic with intention revealing names. Ease of use and sticking to datomic's principles are encouraged.
MIT License
49 stars 7 forks source link

Example in README not working #7

Closed devth closed 11 years ago

devth commented 11 years ago

I pasted the example from the README in my REPL but ran into this exception as soon as I try to use any of the fns created by (dc/create-model-fns model-namespace):

ClassCastException clojure.lang.Var$Unbound cannot be cast to datomic.Connection  datomic.api/transact (api.clj:64)

Using this variant to create the db:

(ns server)
(require '[datomico.core :as dc])
(dc/start {:uri "datomic:mem://my-app"
           :schemas [models.user/schema]})

If I instead use this variant, it works:

(ns user)
(require '[datomico.core :as dc])
(dc/start {:dynamic-vars true
           :schemas [models.user/schema]})

I'm running into the same exception in my actual code as well, trying to connect to a datomic-free transactor. Looks like dc/start with :dynamic-vars properly returns a datomico.db/entity while specifying a :uri returns nil.

Using the 0.1.0 release.

Edit: It looks like I'm missing something fundamental about how to set the dynamic *db* value. Apparently :dynamic-vars true does this for you but is "Not recommended for application code. Default is false." What is the correct way to set *db* and why wouldn't you always want it to be the most recent db version by default?

cldwalker commented 11 years ago

Hey. Sorry for the delay. The first variant is not meant to be used from a repl and requires explicit handling of connection and db. It assumes it's a web app and that you would be wrapping your middleware with wrap-datomic. I'll update the docs to be more clear.

To answer your question about, why you don't want to do this by default requires looking into what happens when you use :dynamic-vars. On every query, it creates a new db object to be passed to datomic. While this is a nice convenience, you should be using wrap-datomic or something that explicitly handles updating db and connection as needed.

devth commented 11 years ago

Got it, thanks.