Fork me on GitHub
#datomic
<
2016-05-02
>
grounded_sage13:05:08

Im looking into different databases to learn them and I was wondering if Datomic is an in memory database what happens when it goes down or restarts?

bostonaholic13:05:09

@grounded_sage: the in-memory database is typically only used for experimentation and testing

Ben Kamphaus13:05:34

If you're talking about the mem storage, right, it isn't durable. If you're referring to the db being cached in memory on peers, it's still on durable storage and the cache will be repopulated as segments are read on the peer after restart.

jgdavey18:05:29

Can anyone refresh my memory about how to pass a “predicate” into query? I know there are other ways, but wanted, if possible to use a predicate within the query itself.

jgdavey18:05:22

That is: ’[:find ?e :in $ ?pred :where [?e :foo/bar ?val] [(?pred ?val)]]

jgdavey18:05:51

That obviously doesn’t work, but I think illustrates what I’m going for

Ben Kamphaus18:05:13

just define it outside query and fully namespace it when you invoke it in the query.

jgdavey18:05:40

So anonymous functions are out?

Ben Kamphaus19:05:03

hmm, haven’t tried or tested anonymous functions in query before, now I’m curious myself… simple_smile

Ben Kamphaus19:05:58

@jgdavey: so I was able to do it with a user defined generic predicate applier (ignore the fact that the toy example could be replicated with a provided comparison operator):

(defn apply-pred [some-fn x]
  (some-fn x))

(d/q '[:find ?name ?year
       :in $ ?fn
       :where 
       [?a :artist/name "Pink Floyd"]
       [?r :release/artists ?a]
       [?r :release/name ?name]
       [?r :release/year ?year]
       [(user/apply-pred ?fn ?year)]]
     (d/db conn) #(< 1972 %))

pheuter22:05:26

So I’m trying to do an “upsert” in a transaction using the list form and am getting the following error: :db.error/not-an-entity Unable to resolve entity. Does that mean the entity id does not exist in the database or that i’m not specifying it properly? This is what the transaction list looks like: [:db/add [:user/email “some email”] a v]

Ben Kamphaus22:05:02

@pheuter an entity has to exist for a lookup ref to work. An upsert would be that attr val asserted for an entity with a tempid (typically in map form) and the tempid would resolve to the entity that already exists in the event that that unique identifier is already in the db.

pheuter22:05:10

right, that makes sense, i guess i’m wondering if my list form is properly setup, specifically that i can specify a vector containing a unique attribute and its value as an entity id.

taylor.sando22:05:45

Can you pass anonymous functions to a transactor function? I know the transactor can run namespaced functions as long as they are on the classpath. I was thinking that you could make a transactor function called validate/fn, which you could call with the arguments, :query, :params, :error-msg, checker-fn. In the actual function you would do (apply datomic.api/q db (:query params) (:params params)), then you would check the result returned against the checker fn, which, depending whether it was true or false, could raise an exception to reject the transaction.

taylor.sando23:05:30

I can do it locally, but on my dev database I'm getting a illegal argument exception from a fressian write handler. Is it trying to serialize the transaction when sending to the remote transactor, but not locally? I kind of assumed you wouldn't be able to pass a function to the transactor, but wanted to try it.