Fork me on GitHub
#datomic
<
2020-10-28
>
vncz14:10:24

Is there a way to DRY these two queries? They look almost identical apart from the id parameter. Is there a way without having to manipulate the list manually?

vncz14:10:38

Well I can probably get away with it by using the map form, but I was wondering whether there's a better way :thinking_face:

favila14:10:56

I question whether this is better, but it is DRY:

favila14:10:04

(defn people [db person-pull person-ids]
  (d/q '[:find (pull ?e person-pull)
         :in $ person-pull ?ids
         :where
         (or-join [?e ?ids]
                  (and [(= ?ids *)]
                       [?e :person/id])
                  (and [(!= ?ids *)]
                       [(identity ?ids) [?id ...]]
                       [?e :person/id ?id]))]
       db
       person-pull
       person-ids))

favila14:10:21

use the special id value * to mean “everyone”

favila14:10:43

otherwise it’s a vector of entity identifiers

vncz15:10:54

Hmm does not seem worth the hassle. I was thinking of using the map form and manually inject the parameter @U09R86PA4 …what do you think?

favila15:10:50

there may be a penalty from not caching the query plan, since each query is a new instance. But I’m not sure if cache lookup is by identity or by value

vncz16:10:49

Got it. good point. Seems like a case where duplication is cheaper than the wrong abstraction 🙂

ghadi14:10:17

Use d/pull directly with the first form

vncz14:10:01

Can I? I do not really have the entity id, I have my "internal" id

favila14:10:36

pull (and most things) can take any entity identifier, which includes entity ids, idents, and lookup refs. In your case, (d/pull db [:person/id :person/name :person/surname] [:person/id "the-id"]) would work

vncz15:10:56

Ah interesting, that I didn't know. Thanks!

ghadi14:10:42

Rather than pull in the find spec of a query

vncz14:10:01

Can I? I do not really have the entity id, I have my "internal" id

vncz14:10:47

I was thinking that if I would be switching to map form I could manipulate the query easily and add the parameter?

Aleh Atsman15:10:03

Hello, can somebody clarify for me the purpose of cast/event , is it only for infrastructure level events or can it be used for application level events as well?

joshkh17:10:37

someone else can correct me if i'm wrong, but i use cast/event for all sorts of things including application level logging

jaret18:10:37

@U4N27TADS to echo what Josh is saying it's for ordinary occurrences of interest to the operator. Whereas an Alert is for an extraordinary occurrence that requires operator intervention. These are conventions you can choose to follow or not in your use of the ion.cast.

Aleh Atsman14:10:59

Hello @U0GC1C09L, @U1QJACBUM! Thank you for explanation. In the end we decided to go with event bridge or sns topic directly. It is problematic to route events from cloudwatch logs to aws lambda functions. As the only option there is subscription filter (max 2 per log group). Maybe I missing something, but haven't found solution where I am able to get events submitted using cast/event to lambda functions.

joshkh14:10:31

i don't know if this is useful to you, but we cast/alert exceptions to CloudWatch, and then use a CLJS Lambda to send them to Slack to torture our developers. cast/events are not really any different, except for maybe the frequency at which they appear, but i think log streams are batched. (sorry for the lack of a proper README, it was a hobby project) https://github.com/joshkh/datomic-alerts-to-slack > It is problematic to route events from cloudwatch logs to aws lambda functions. As the only option there is subscription filter (max 2 per log group). for application level logs and alerts, we tend to the use a common message throughout the application (e.g. {:msg "<app-name>-application-log"} ) , and then we attach other keys such as :env and :query-group . this provides us different levels of filtering while keeping our logs all in one place

joshkh14:10:23

but if SNS works for you then go for it! 🙂 i just prefer CloudWatch because cast serialises Clojure to JSON very well, and being able to add arbitrary keys at any level is useful for filtering