Fork me on GitHub
#datomic
<
2021-06-19
>
joshkh07:06:28

can i pass a rule name into a query as an argument without a macro?

(d/q '{:find  [?player]
       :in    [$ % ?rule-name ?player-name]
       :where [[?player :player/name ?player-name]
               (?rule-name ?player)]}
     db rules 'is-player "player1") 

Execution error (IllegalArgumentException) at datomic.core.datalog/resolve-id (datalog.clj:330).
Cannot resolve key: is-player

Joe Lane19:06:19

Use clojure to construct the query as data

(defn query-players
  [db rules player-name wants-is-player-rule?]
  (->
   (cond->
       '{:find  [?player]
         :in    [$ % ?player-name]
         :where [[?player :player/name ?player-name]]}
     wants-is-player-rule? (update :where conj '(?is-player ?player)))
   (d/q db rules player-name)))

(query-players (d/db conn) the-rules "player1" true)

kenny15:06:15

Can you rely upon the Datomic Cloud endpoint address always following the format: .<system>.<region>. ?

Joe Lane17:06:27

No, it’s an address, addresses can change.

kenny19:06:20

Oh interesting. When does it change at the moment? What’s the migration strategy to go from one format to another?

Joe Lane19:06:05

At the moment it doesn't, but you asked if you can rely on the endpoint address "ALWAYS" following that format.

kenny20:06:59

I see. If it were to change, how could that be done safely?

Joe Lane20:06:18

It’s just a different string. What if the endpoint had a uuid in it? I’m not sure what you mean by “safely”.

kenny20:06:21

If it were to change, client applications would need to know about which endpoint to point to. By safely I mean informing the client application which endpoint it should use before and after the switch.

Joe Lane22:06:29

“Client applications” meaning not ions?

Joe Lane22:06:01

How do they know what endpoint to hit right now?

kenny22:06:46

Statically defined string at startup. Seems like a switch of that endpoint would be require application downtime.

Joe Lane22:06:48

Doubtful. That statement is only true because you aren’t using a mechanism to dynamically update that endpoint and the datomic client using it.

Joe Lane22:06:55

Imagine switching the query groups your client applications point to with zero downtime. How would you do it?

kenny00:06:18

Oh I see. You’re saying in the event Datomic changes it’s endpoint, we’d need to do an A B switchover by deploying an entirely new query group?

Joe Lane01:06:11

That in combination with either deploying a separate set of client applications pointed at the new QG or having your client applications being able to reset their clients and connections by polling for config values at a low rate (15 mins)