datomic

Ask questions on the official Q&A site at https://ask.datomic.com!
promesante 2020-11-24T07:13:11.484600Z

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

danieroux 2020-11-24T08:21:03.485200Z

https://docs.datomic.com/cloud/transactions/transaction-functions.html is maybe what you are looking for

2020-11-24T09:47:14.489100Z

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.

promesante 2020-11-24T09:47:21.489200Z

@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

promesante 2020-11-24T09:53:44.491600Z

@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

2020-11-24T09:58:11.491800Z

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

jaret 2020-11-24T18:32:41.493Z

Datomic 1.0.622 On-Prem now available: https://forum.datomic.com/t/datomic-1-0-6222-now-available/1700

tvaughan 2020-11-24T19:25:03.495Z

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

tvaughan 2020-11-25T11:10:28.001200Z

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

kschltz 2020-11-26T13:29:08.004900Z

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

2020-11-26T17:52:54.012200Z

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

👍 1
tvaughan 2020-11-27T12:25:42.019800Z

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

2020-11-27T12:34:58.020Z

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 ["<http://127.0.0.1:9200>"]}, "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.

2020-11-27T12:35:21.020200Z

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

tvaughan 2020-11-27T12:46:27.020700Z

Nice! Thanks for sharing this!

pyry 2020-11-24T20:34:17.496Z

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.

pyry 2020-11-24T20:36:05.496200Z

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.

bbrinck 2020-11-24T22:55:08.499700Z

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)

bbrinck 2020-11-24T22:55:23.499800Z

Here is my code:

#!/bin/sh

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

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

(require '[datomic.client.api :as d]
         '[datomic.dev-local :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))))

(ct/run-tests)

favila 2020-11-24T22:59:08Z

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

favila 2020-11-24T22:59:20.000200Z

try (shutdown-agents) at the end

bbrinck 2020-11-24T22:59:30.000400Z

Works perfectly, thank you!!!!

promesante 2020-11-24T23:10:24.000600Z

understood, thanks

promesante 2020-11-24T23:10:40.000800Z

understood, thanks