This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-23
Channels
- # beginners (63)
- # cljs-dev (1)
- # cljsjs (1)
- # cljsrn (11)
- # clojure (208)
- # clojure-berlin (2)
- # clojure-dusseldorf (5)
- # clojure-italy (5)
- # clojure-norway (56)
- # clojure-russia (7)
- # clojure-spec (85)
- # clojure-uk (27)
- # clojurescript (191)
- # core-async (73)
- # cursive (4)
- # datomic (62)
- # defnpodcast (1)
- # hoplon (2)
- # jobs-rus (1)
- # juxt (14)
- # keechma (1)
- # leiningen (1)
- # lumo (126)
- # off-topic (2)
- # om (11)
- # onyx (27)
- # pedestal (52)
- # planck (21)
- # powderkeg (1)
- # re-frame (32)
- # reagent (14)
- # ring-swagger (1)
- # rum (3)
- # slack-help (19)
- # specter (23)
- # untangled (32)
- # vim (7)
- # yada (43)
Well, I found a way to express, but it's ugly. Hope there is some nicer way to do this! ` :get #vase/query {:name :receipts-server.v1/user-get :params [name abbrev email] :query [:find ?e ?attr ?val ?found-email ?found-name ?found-abbrev ;; DBG :in $ ?name ?abbrev ?email :where [(count ?email) ?n-email] [(count ?name) ?n-name] [(count ?abbrev) ?n-abbrev] [(pos? ?n-email) ?p-email] [(pos? ?n-name) ?p-name] [(pos? ?n-abbrev) ?p-abbrev] [(and ?p-email :receipts.user/email) ?attr-email] [(and ?p-name :receipts.user/name) ?attr-name] [(and ?p-abbrev :receipts.user/abbrev) ?attr-abbrev] [(or ?attr-email ?attr-name ?attr-abbrev) ?attr] [(and ?p-email ?email) ?val-email] [(and ?p-name ?name) ?val-name] [(and ?p-abbrev ?abbrev) ?val-abbrev] [(or ?val-email ?val-name ?val-abbrev) ?val] [?e ?attr ?val] [?e :receipts.user/email ?found-email] ;; DBG [?e :receipts.user/name ?found-name] ;; DBG [?e :receipts.user/abbrev ?found-abbrev] ;; DBG ]} `
(This is for a slightly harder case than what I asked -- three parameters)
And, it still requires that the client pass in the empty parameters too, e.g.
@deg I did get a chance to explore using optional parameters with an or
in a query. Here’s a snippet https://gist.github.com/ddeaguiar/d93a81282b60a261a2afb53262a3aeeb
You can specify default values for parameters by using a vector instead of a symbol for the parameter
[[foo :some-default] bar]
Thanks. I did not know about the ability to supply default values. Not yet documented? Or did I just miss it in the docs?
Re using :or-join, I did try something similar, which failed, but did not checkpoint that attempt so I'm not sure what I did wrong. (The error was something about using different variables in the two clauses, but I think I did about what you did, so dunno)
When you use an or
clause in Datomic queries, all the clauses within it need to use the same set of variables
I’d recommend avoiding overly generalized queries. Queries that include predicates like [?e ?attr ?val]
I also notice your (pull ?e [*])
clause. I had found pull mentioned in some datomic doc, but had not been able to get the arguments to work for me. Again, I'm puzzled, because I think I tried the same thing in one of my attempts, but it wanted another arg. In any event, pull
is also something that should be in the mythical doc I keep harping on.
In any event, I'm not tweaking your sample to make sure it works in my file. I'm confused that it looks so close to what I had, yet mine didn't work. Should take me another 2-3 minutes.
Here’s a list of some query best practices http://docs.datomic.com/best-practices.html#most-selective-clauses-first
Since Vase is based on Datomic and Pedestal, It’s difficult to determine what’s the essential information to pull from each tech for documentation purposes. Here’s info on pull http://docs.datomic.com/pull.html
And here’s more on pull in the context of queries http://docs.datomic.com/query.html#pull-expressions
I wonder what I did different yesterday, but never gonna know. Probably required the exact level of ignorance I had then.
one thing is that if email and id are provided and each match a different user, then you’ll get two records back
Is there some way to ensure only one is passed in? I suppose that would be done with a one-liner interceptor?
ok. Don't do so on my behalf; I'm already well past what I need for this toy learning app. But, if you want to expand the docs, it would certainly be great to see examples of this sort. Thanks!
Just checking, because using multiple parameters with query actions is broken on the current, stable release
@deg You may enjoy some new Datomic training videos we released today: http://blog.datomic.com/2017/03/new-datomic-training-videos-and-getting.html
@deg, btw, I realize that my contrived example shared in the gist was based on your desire to use multiple parameters in an or-like way. I’ve updated the gist to indicate how I’d likely implement support for looking up a user by email or id. https://gist.github.com/ddeaguiar/d93a81282b60a261a2afb53262a3aeeb
I see. Definitely cleaner, for this case; though I was doing this more as a contrived example. Of course, don't forget my friend, Mr. <mailto:[email protected]|[email protected]>. (He's a cousin of Little Bobby Tables (https://xkcd.com/327/).