Fork me on GitHub
#datomic
<
2016-08-01
>
davin14:08:33

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:

davin14:08:52

(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 “"]]])))

davin14:08:07

Is there something simple I’m missing? I’m new to datomic.

davin14:08:35

the :author/email is marked as identity

yonatanel14:08:50

@davin: what's the error?

davin14:08:15

Yeah, that’s the strange thing. It isn’t throwing an error, but I don’t see a registered transaction in the console either

davin14:08:35

I’m running everything locally with bin scripts

Lambda/Sierra14:08:51

d/transact returns a Future, you won't see an error unless you deref it.

davin14:08:15

@stuartsierra: ok I’ll pipe to deref and see what comes back, thanks

yonatanel14:08:43

@davin: aren't you mixing list form and map form of transaction?

davin14:08:28

@yonatanel: I might be, I’m not familiar enough with it yet to know the difference 🙂

marshall14:08:58

@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.

davin14:08:43

thanks both of you, I’ll have a look at the link

marshall14:08:44

You also want to be careful defining a connection inside a function that transacts

davin14:08:37

@marshall: I’m refreshing the conn everytime until I’m more familiar, what do you recommend?

marshall14:08:20

Managing things like your connection is something people often use tools like Stuart Sierra’s Component for https://github.com/stuartsierra/component

marshall14:08:02

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/)

davin14:08:25

Thanks @yonatanel @stuartsierra and @marshall, it was the list vs map form that was the problem. 🙂

davin14:08:04

Thanks @marshall I’ll read everything you linked to

Lambda/Sierra14:08:07

Also, don't def inside another defdef is always global, regardless of where it appears.

davin14:08:51

Yes, the def inside did seem weird, I probably meant it to be a let

davin15:08:20

Will the conn timeout at some point?

davin15:08:35

if it is defined more globally?

yonatanel15:08:03

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?

timothypratley16:08:34

Is it possible to write a retraction query, like 'retract all entities that have a :from attribute 1'?

timothypratley16:08:36

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)

timothypratley16:08:00

when I [:db.fn/retractEntity 1]

timothypratley16:08:00

(I'm using DataScript, so maybe it is just a missing feature, hmmm I shall try it in Datomic proper)

timothypratley18:08:16

@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.

timothypratley18:08:14

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.

marshall18:08:38

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

marshall18:08:19

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

timothypratley18:08:48

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.

kenny21:08:05

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?

kenny21:08:01

I am running the transactor locally and I am running create-database in a REPL.

kenny21:08:39

Also, I'm using datomic 0.9.5385

kenny21:08:57

Also probably relevant: I can create a test database using Datomic shell

kenny21:08:52

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.

kenny22:08:30

Hmm.. just updated to 1.11.22 and it worked. You guys should update the docs.

shinych22:08:03

Hi all, how possible is it to run Datomic on DB2?