Fork me on GitHub

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?


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


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.


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.


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


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


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


So anonymous functions are out?


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


@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
       [?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 %))


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]


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


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.


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.


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.