Fork me on GitHub

hi, how could I update the value of an attribute by applying a function on it, like in a Clojure atom, instead of just replacing it with a new value, thanks


understood, thanks

Lennart Buit09:11:14

You could also do [:db/cas …], in which you specify your expected old value, as well as the new one. E.g. “If the account balance was 6 euros, then the account balance should now become 9 euros”. If you expectancy is not met, you’ll get an exception.


@danie thanks for the quick reply ! it seems so, but perhaps a bit too compact for someone new to Datomic like me, I'd need a clearer, complete example, thanks


@lennart.buit thanks for your quick reply ! what I am trying to implement is just apply a function to current value and get that replaced by that function application's output

Lennart Buit09:11:11

Yeah, you can do that, just pull the current value, apply your function, and compare-and-swap old to new.


understood, thanks


What's the recommended solution, if there is one, for free form text search across multiple attributes? Bonus points for different matching algorithms and weighted results. Has anyone attempted to integrate Datomic with Elasticsearch? Thanks


Well, I'd say Elasticsearch is indeed a good choice, giving you a lot of flexibility for text search across multiple attributes straight out of the box.


There shouldn't be any issues with using Elasticseach with Datomic if you use the standard practice of storing your data in a real database (eg. Datomic) and only using Elasticsearch as a secondary view to the data.


+1 for pyry’s suggestion, keeping an index outside of the main Datomic database


Thanks. I worked with Postgres and Elasticsearch and this is the approach we took then too.


We use datomic cloud + elastic search in a similar scenario described by pyry. It suits us just fine


We use elastic search for the same purpose too. Even embedding the ES query inside datalog, so the queries are from the peer. This way the datomic client consumers do not need ES integration

👍 4

@UHJH8MG6S I was hoping to hear something like this. Can you share any more details? An example maybe?


Basically we created a 2 (internal) libraries. 1 for monitoring the tx-log, and updating those values into ES. The other exposes some search functions (uses spandex to perform a query). We put that library on the classpath of our peer server. Which allows the client to use the functions in our internal library to be used in datalog:

{:query '{:find [?e] 
          :where [(ourthing/search ?client ?search-term) [?e ...]]
          :in [$ ?client ?search-term]}
 :args [(d/db ...), {:hosts [""]}, "Hello world!"]}
In order to get this to work we built a second (internal) library which monitors the tx log, and updates ES indexes for any attributes we're interested in searching.


Most of this is very much WIP, but as far as I can tell right now it's a very viable solution.


Nice! Thanks for sharing this!


I’m trying to use dev-local to write a test that involves a datomic database. I can open the connection and get a database, but when my code is done running, the program waits for about 30-40s before it completes. Presumably this is because I’ve failed to shut down something related to datomic, but I cannot figure out how to close the connection or otherwise shut down the dev-local database. (Note: if I never call datomic.client.api/connect, the program shuts down immediately)


Here is my code:


#_DEPS is same format as deps.edn. Multiline is okay.
   {:deps {com.datomic/dev-local {:mvn/version "0.9.225"}
#_You can put other options here

exec clojure $OPTS -Sdeps "$DEPS" "$0" "$@"

(require '[datomic.client.api :as d]
         '[ :as dl]
         '[clojure.test :as ct :refer [is testing deftest use-fixtures]])

(deftest datomic-integration
  (let [args {:server-type :dev-local
              :system "test"
              :db-name "movies"
        client (d/client args)
        _ (d/create-database client args)
        ;; If I don't call connect, the script exits immediately after
        ;; the tests run.
        conn (d/connect client args) 

    (println (class conn)) ;; datomic.dev_local.impl.DurableConnection
    (dl/release-db args)

    (is (= 1 1))))



If a clojure process is idle for 60 seconds before shutting down, it’s almost always the agent thread pool


try (shutdown-agents) at the end


Works perfectly, thank you!!!!