This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-22
Channels
- # beginners (43)
- # bristol-clojurians (2)
- # calva (11)
- # cider (10)
- # clj-kondo (3)
- # clojars (19)
- # clojure (93)
- # clojure-france (44)
- # clojure-nl (10)
- # clojure-uk (15)
- # clojuredesign-podcast (1)
- # clr (6)
- # core-typed (102)
- # data-science (1)
- # datomic (11)
- # docker (4)
- # emacs (12)
- # fulcro (27)
- # graalvm (6)
- # joker (1)
- # leiningen (4)
- # lumo (20)
- # nrepl (3)
- # off-topic (63)
- # parinfer (4)
- # reagent (40)
- # remote-jobs (2)
- # shadow-cljs (18)
- # spacemacs (7)
- # tree-sitter (7)
- # yada (3)
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?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
I'm using on-prem, following this tutorial which is passing a map: https://docs.datomic.com/on-prem/tutorial.html
You should write a function that outputs the tx-data so that you can inspect it before transacting
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"}]
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')
does this hit the spot? https://stackoverflow.com/a/53360679
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??
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.