Clojurians
#datomic
<
2017-05-31
>

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

ezmiller7704:05:05

Is it possible to pass a _ as an input in a parameterized query?

favila07:05:52

@ezmiller77 can you be more concrete? You want [:in $ _ ]? or a symbol _ as a value?

favila07:05:43

first is probably no, but I'm not sure why you would want to do that. Second is definitely yes.

ezmiller7707:05:45

@favila: More like :in $ ?type, where ?type is a wildcard _ from the input arg passed to the query fn when I want not to filter the results. Because the only other way I know to get all is to construct a separate query.

misha10:05:52

@ezmiller77 what's wrong with separate query?

misha11:05:07

is there a way to sort entities by creation date w/o storing some extra :e/created-date attribute value? is sorting by id good enough proxy for this? say, I have event, with a collection of subevents. actual dates of subevents are not important, but order of creation is (e.g. for further reduction).

misha11:05:17

use case example would be order of operations: 100% -10 -20% is not the same as 100% -20% -10 (72 vs 70)

robert-stuttaford12:05:19

entity ids will always be larger if they are newer @misha

souenzzo12:05:40

ezmiller77: (d/q '[:find ?e :in $ param :where [?e :user/id param]] db (quote _))

misha12:05:20

@robert-stuttaford will ids (order) be preserved during built-in backup/restore?

robert-stuttaford13:05:55

@marshall or @jaret can confirm for you @misha

jaret13:05:31

I don't believe so. One sec let me confirm.

jaret13:05:21

Nevermind they are wholly preserved

jaret13:05:17

So the order of entity IDs is preserved during backup/restore

favila13:05:40

Ah. No that is essentially the "nil" case. You must construct a separate query. I use cond-> when I create the clauses

souenzzo13:05:46

My attempt does not work :disappointed:

favila14:05:16

_ as data is not the same as _ as syntax

favila14:05:44

your query looks for a user-id equal to the symbol _

favila14:05:54

which nothing will be

favila14:05:10

even using an empty collection for param won't work

favila14:05:05

(defn q-users [db user-id]
  {:query {:find  '[[?e ...]]
           :in    (cond-> '[$]
                    user-id (conj '?id))
           :where (cond-> []
                    user-id (conj '[?e :user/id ?id])
                    (not user-id) (conj '[?e :user/id]))}
   :input (cond-> [db]
            user-id (conj user-id))})

favila14:05:11

(for example)

favila14:05:59

(d/query (q-users db nil)) or (d/query (q-users db "some-id")

robert-stuttaford16:05:02

thanks @jaret! fyi ^ @misha

kschrader18:05:20

@jaret is that just current behavior or is that a design decision that can be relied on going forward?

jaret18:05:51

relied upon