Fork me on GitHub
#datomic
<
2020-11-24
>
promesante07:11:11

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

promesante23:11:40

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.

promesante09:11:21

@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

promesante09:11:44

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

promesante23:11:24

understood, thanks

tvaughan19:11:03

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

pyry20:11:17

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.

pyry20:11:05

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.

bhurlow01:11:31

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

tvaughan11:11:28

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

kschltz13:11:08

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

thumbnail17:11:54

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
tvaughan12:11:42

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

thumbnail12:11:58

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.

thumbnail12:11:21

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

tvaughan12:11:27

Nice! Thanks for sharing this!

bbrinck22:11:08

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)

bbrinck22:11:23

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)

favila22:11:08

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

favila22:11:20

try (shutdown-agents) at the end

bbrinck22:11:30

Works perfectly, thank you!!!!