This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-01
Channels
- # admin-announcements (8)
- # arachne (11)
- # beginners (17)
- # boot (64)
- # cider (26)
- # cljs-dev (7)
- # cljsrn (1)
- # clojure (115)
- # clojure-belgium (2)
- # clojure-dusseldorf (15)
- # clojure-poland (15)
- # clojure-russia (62)
- # clojure-spec (86)
- # clojure-uk (208)
- # clojurescript (36)
- # cursive (4)
- # datavis (11)
- # datomic (44)
- # editors (9)
- # hoplon (21)
- # jobs (4)
- # mount (21)
- # off-topic (3)
- # om (113)
- # onyx (65)
- # parinfer (2)
- # perun (3)
- # proton (6)
- # re-frame (29)
- # reagent (20)
- # yada (3)
hi all. I’m having a bit of trouble with what I thought would be a simple create transaction, creating a post
entity with an existing author
:
(defn createPost [id to-be-created]
(def conn (d/connect (:db-uri env)))
(let [post-body (:body to-be-created)
post-name (:name to-be-created)]
(d/transact
conn
[[:db/add (d/tempid :db.part/user)
:post/public-id id
:post/body post-body
:post/name post-name
:post/author [:author/email “"]]])))
Yeah, that’s the strange thing. It isn’t throwing an error, but I don’t see a registered transaction in the console either
d/transact
returns a Future, you won't see an error unless you deref it.
@stuartsierra: ok I’ll pipe to deref
and see what comes back, thanks
@yonatanel: I might be, I’m not familiar enough with it yet to know the difference 🙂
@davin: @yonatanel is correct. You look to be using the map form, but it’s in a list. You can replace the :db/add
with :db/id
and turn the whole thing into a map.
@marshall: I’m refreshing the conn
everytime until I’m more familiar, what do you recommend?
Managing things like your connection is something people often use tools like Stuart Sierra’s Component for https://github.com/stuartsierra/component
In general the connection is something shared across your program, so defining it in a single function is not ideal. Functions that transact data should probably take a connection as an argument, but also keep in mind you’ll want to be careful about that if all you’re doing is reading (http://www.rkn.io/2014/02/10/datomic-antipatterns-connnnn/)
Thanks @yonatanel @stuartsierra and @marshall, it was the list
vs map
form that was the problem. 🙂
Also, don't def
inside another def
— def
is always global, regardless of where it appears.
Is there a datomic cookbook or something similar except the best practices section of the docs, with explanation of each solution and addressing performance, indexes, gotchas etc?
Is it possible to write a retraction query, like 'retract all entities that have a :from attribute 1'?
and/or if I have a schema like:
(def schema
{:to {:db/type :db.type/ref}
:from {:db/type :db.type/ref}})
should it have been retracted automatically? (seeing it was a ref)when I [:db.fn/retractEntity 1]
(I'm using DataScript, so maybe it is just a missing feature, hmmm I shall try it in Datomic proper)
@timothypratley: You might want to look at the retractEntity database function: http://docs.datomic.com/transactions.html#built-in-transaction-functions
@marshall right, rectractEntity appears to only work with a provided id or lookup ref, what I'm wondering is whether I need to do 2 steps: a) lookup all the entities, b) retract them... or if there is some way to in a single transaction identify and retract them together.
In this case I'm representing nodes and edges. When deleting a node, some edges become invalid and need to be removed. So I find the edges and remove them. But it seems like it should be possible to do it in a transaction, instead of as a lookup + transaction.
retractEntity will remove all references from and to a given entity it does this by retracting all datoms with that entity ID in either the e or v position if you need to retract more than one entity this way, then yes, you’ll need to create a list of them (presumably via query) and call retractEntity on each
if you want it all to occur in a single transaction, you can write a transaction function that does the lookup and calls retractEntity on all results of the lookup
ah so in the case above it removes the :from, but leaves the :to (which might point to 2) -- which is an invalid edge -- so I need to go with writing a transaction function, thanks.
I am getting java.lang.NoClassDefFoundError: Could not initialize class datomic.ddb_cluster__init
when calling (d/create-database "datomic:
. Is there something else I need to do besides adding com.amazonaws/aws-java-sdk-dynamodb
to my project?
Hmm.. After restarting the REPL, the first time I run create-database
I get java.lang.ClassNotFoundException: com.amazonaws.DnsResolver
but every following time I run create-database
I get the previous error, java.lang.NoClassDefFoundError: Could not initialize class datomic.ddb_cluster__init
.