Fork me on GitHub
#datomic
<
2020-02-22
>
dvingo00:02:59

sooooo. redeploying the ion app seems to have magically fixed things

coby17:02:10

Hey folks, Datomic n00b here. I'm working inside a simple demo app generated with lein new luminus luminus-example +datomic. (It generated the db-core ns called below, where my conn lives.) I can run queries just fine but can't transact. When I call this code:

(defn create-post! [{:keys [type title slug content]}]
  (let [id (java.util.UUID/randomUUID)
        type (or type :page)
        title (or title (str "Page " id))
        slug (or slug (title->slug title))
        content (or content [])]
    (d/transact db-core/conn {:tx-data [{:post/id id
                                         :post/type type
                                         :post/slug slug
                                         :post/title title
                                         :post/content content}
                                        {:db/add "datomic.tx"
                                         :db/doc "create post"}]})))

(create-post! {})
I get:
Execution error (ClassCastException) at datomic.api/transact (api.clj:96).
class clojure.lang.PersistentArrayMap cannot be cast to class java.util.List (clojure.lang.PersistentArrayMap is in unnamed module of loader 'app'; java.util.List is in module java.base of loader 'bootstrap')
Am I doing something obviously wrong? Which map is it trying to cast to a list?

markaddleman17:02:25

Are you using Datomic Cloud or on-prem? I believe the APIs for those two are a bit different. Specifically, the second argument to transact is a map in Cloud but I do not think it is in on-prem

coby19:02:06

I'm using on-prem, following this tutorial which is passing a map: https://docs.datomic.com/on-prem/tutorial.html

ghadi23:02:04

You should write a function that outputs the tx-data so that you can inspect it before transacting

ghadi23:02:31

try to pull apart things that transact from things that generate tx data

coby05:02:59

I actually did try that and got what I expected.

(create-post-data {})
  ;; => [#:post{:id #uuid "b05f2baa-ec01-485c-91cc-abf2f8fe5256",
  ;;            :type :page,
  ;;            :slug "page-b05f2baa-ec01-485c-91cc-abf2f8fe5256",
  ;;            :title "Page b05f2baa-ec01-485c-91cc-abf2f8fe5256",
  ;;            :content []}
  ;;     #:db{:add "datomic.tx", :doc "create post"}]

  (create-post-data {:type :page :title "New Page!"})
  ;; => [#:post{:id #uuid "5665a149-90cf-42ff-bef1-a10d46881a3e",
  ;;            :type :page,
  ;;            :slug "new-page!",
  ;;            :title "New Page!",
  ;;            :content []}
  ;;     #:db{:add "datomic.tx", :doc "create post"}]

  (create-post-data {:type :page :title "New Page!" :slug "new-page" :content ["some" "content"]})
  ;; => [#:post{:id #uuid "82a510c7-8160-4e22-96fd-74d15239ef8b",
  ;;            :type :page,
  ;;            :slug "new-page",
  ;;            :title "New Page!",
  ;;            :content ["some" "content"]}
  ;;     #:db{:add "datomic.tx", :doc "create post"}]

coby05:02:04

Hmm, this seems to be a deeper issue that's not related to create-post! at all. I'm getting it for any call to transact.

(d/transact db-core/conn
            {:tx-data
             [[:db/add
               [:post/id #uuid "b2e32ece-c6b6-4936-ba39-d24f717dcd4d"]
               :post/slug "updated-slug"]]})
;; => Execution error (ClassCastException) at datomic.api/transact (api.clj:96).
;;    class clojure.lang.PersistentArrayMap cannot be cast to class java.util.List (clojure.lang.PersistentArrayMap is in unnamed module of loader 'app'; java.util.List is in module java.base of loader 'bootstrap')

coby18:02:25

yep, that sounds like exactly my issue. So here's my understanding: • running bin/run -m datomic.peer-server ... and connecting per the tutorial uses the Client API (map version) • My Luminus app is using the "in-process peer library" as described here: https://docs.datomic.com/on-prem/clients-and-peers.html • Seems like the recommendation is to go with the Client API...which is still in alpha??

currentoor19:02:44

Has anyone used datascript as a write-through-cache for datomic to achieve offline mode? I’m building a POS, clients are react native iOS. Datascript (persisted in client-side blob store) as a write-through cache seems compelling because then I can write most of my queries in CLJC and re-use them on client and server. And in offline mode I can restrict the POS to only allow accretion of new data, so I don’t have deal with DB conflicts.