Fork me on GitHub
#datomic
<
2019-04-25
>
benoit11:04:51

@joe.lane Throwing would work but why can't you detect that your tx is empty and not send it to the transactor in the first place?

Cas Shun13:04:57

I have a datomic cloud database with a bunch of {:db/ident :loc/gb} {:db/ident :loc/us} etc... used as enumerable values. How can I find out all available values in the :loc namespace that are available in the db? i.e. I want to find all countries in the existing schema.

Ivar Refsdal13:04:04

I think

(d/q '[:find [?attr ...]
       :in $
       :where
       [?e :db/ident ?attr]
       [(datomic.Util/namespace ?attr) ?ns]
       [(= ?ns "loc")]]
     (d/db conn))
will do the job

Cas Shun13:04:56

won't work in cloud

Cas Shun13:04:28

database functions not supported in cloud (yet?)

Ivar Refsdal13:04:27

Oh, sorry, I'm not familiar with cloud. Maybe someone else is... Would this work: ?

(->> (d/q '[:find [?ident ...]
            :in $
            :where
            [?e :db/ident ?ident]]
          (d/db conn))
     (filter #(= "loc" (namespace %))))

Cas Shun13:04:13

ah, i think that's the right idea yes

favila14:04:02

Consider making an "enum entity" that references all these idents

favila14:04:08

or the other way around

marshall14:04:02

Cloud does indeed support db functions if you prefer that route: https://docs.datomic.com/cloud/query/query-data-reference.html#deploying

marshall14:04:07

grr sorry wrong link

favila14:04:29

{:db/ident :enum/loc :enum/members [:loc/us ...]}

favila14:04:04

or {:db/ident :loc/us :enum/member-of [:enum/loc ,,,]}

marshall14:04:43

fwiw, I like @U09R86PA4’s approach 🙂

Cas Shun13:04:33

I know how to query for everything used, but I'd like to know what's available

Joe Lane15:04:43

Great question @me1740, I’m hoping to write a single transaction function which will either return nothing to transact or some data to update. The advantage here is leveraging the transactor for its atomicity. In the case where there is nothing to transact I’d like to avoid creating an empty transaction entity. Having nothing to transact is the common path. The whole reason for the question is to avoid increasing the number of datoms in the system with empty transaction entities. It’s a system with n timers firing once per second, where N could scale to thousands (eventually). The callback attached to each timer will check a predicate and, if true, will transact some new state into datomic, if false, it should do nothing. I could augment this system to have a single timer that checks the predicate against all candidate entities, but that runs the risk of overrunning the 1 second timer (eventually) if the number of candidate entities grows large (may not be problematic in practice, need to measure). Throwing to avoid an extra transaction datom may work, but I worry about exception throwing as flow control slowing the transactor down (transactions are notorious perf killers on the jvm), ESPECIALLY since having nothing to transact is the normal case, not the exceptional case.

Joe Lane16:04:07

I think I’ll try to detect if a tx is needed, then try my tx function.

julian22:04:46

I am trying to run d/sync on client and getting

IllegalArgumentException No implementation of method: :sync of protocol: #'datomic.client.api/Connection found for class: datomic.client.impl.shared.Connection  clojure.core/-cache-protocol-fn (core_deftype.clj:583)
client is com.datomic/client-pro "0.8.17"