Fork me on GitHub
#datomic
<
2020-05-05
>
murtaza5204:05:49

a noob question - datomic conn is a value of the db in time. So once I finish running a transaction, and if I want to run a query, do I need to use the new value of the db returned by the transaction ? basically if I have an app which is running queries and doing transactions. can I just have a global conn instantiated once at startup, or do I need to refresh the connection after every transaction ?

favila04:05:08

(d/connection ...) => connection object

favila04:05:43

(d/db connection-object) => database-value

favila04:05:43

When you transact (successfully) against a connection object, a new db value is produced, so yes you need to retrieve it if you want to read the results of the transaction. (The map returned from transact has a db-before and db-after already, too)

favila04:05:11

But the connection object is unchanging—its a resource handle not a value (in fact it is already cached for you)

murtaza5205:05:24

so after a transaction if I want to read the results of the transaction, can I just do (d/db connection-object)instead of saving the db value returned by the transaction ?

Lyn Headley10:05:49

I'm pretty sure the answer is yes but I can't find it in the docs.

murtaza5211:05:40

thanks yup that is how it works

favila11:05:57

If you are using the same connection object (same process or client) yes, but you are guaranteed a db at or after that tx, not the immediate next db

favila11:05:12

If you are on a different process, there may be propagation delays. In that case communicate the t to the other process then use d/sync to get a db guaranteed to be at or after the tx in question

murtaza5211:05:10

thanks for the pointer

murtaza5211:05:15

I am using datomic client api, is there a helper function to generate a squuid ?

naomarik17:05:42

How do I use the collection binding form when performing a query as a map using d/query https://docs.datomic.com/on-prem/query.html#bindings? Just getting this error: Argument ... in :find is not a variable.

favila17:05:29

code? also, are you using the client api? (client api doesn’t support find destructuring)

naomarik17:05:03

(let [where ['[?dealer-id :dealer/listings ?listing-id] '[?listing-id :listing/status :active]] q {:find '[?listing-id '...] :in ['$ '?dealer-id] :where where}] (d/query {:query q :args [(db) 17592186057265]}))

naomarik17:05:34

Using datomic.api

naomarik17:05:53

Query works fine without the ... and using ... in any vector-form queries.

naomarik17:05:37

Ah nevermind, got it...

naomarik17:05:51

(let [where ['[?dealer-id :dealer/listings ?listing-id] '[?listing-id :listing/status :active]] q {:find ['[?listing-id ...]] :in ['$ '?dealer-id] :where where}] (d/query {:query q :args [(db) 17592186057265]}))

favila17:05:20

yeah need extra []

favila17:05:27

to make it a map

kenny19:05:17

Is there a way to tell if an environment is running in Datomic (i.e., as an Ion)?

Aleed19:05:09

would using datomic.ion/get-env or datomic.ion/get-app-info work? what I do specifically rn (for other reasons) is check whether my own (System/getenv "LOCAL_ENV") property has been set, and if it hasn’t I assume it’s running in an Ion. not sure if there’s a better way

kenny19:05:01

That would tell me if the ion library is on the classpath, not if it's running in the Datomic environment. Current thinking is to check for the env var DATOMIC_ENV_MAP

Aleed19:05:51

i think DATOMIC_ENV_MAP is the env var that datomic.ion/get-env retrieves, hence my comment 🙂

kenny19:05:26

Right but the difference is substantial. I may have Datomic ion lib on the classpath and not have the env var set.

Aleed19:05:54

i’m not sure I follow (from my understanding DATOMIC_ENV_MAP is set by Datomic system, datomic.ion/get-env just checks whether the env var is set or not which seems to be what you proposed to do anyway). in either case, was just suggesting a possible solution, maybe someone else can comment better

kenny19:05:00

Oh I see what you mean. I can't call out to the Ion lib since it might not be on the classpath. I'm trying to extend our logging library to know to log using Ion's log functions when in the Ion environment.