Fork me on GitHub
#pedestal
<
2017-03-23
>
deg11:03:45

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 ]} `

deg11:03:15

(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.

ddeaguiar13:03:31

@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

ddeaguiar13:03:07

You can specify default values for parameters by using a vector instead of a symbol for the parameter

[[foo :some-default] bar]

ddeaguiar13:03:31

the first member of the vector will be the parameter and the second is the default

deg13:03:39

Thanks. I did not know about the ability to supply default values. Not yet documented? Or did I just miss it in the docs?

deg13:03:16

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)

ddeaguiar13:03:21

hmm I don’t see that in the docs but I may have missed it

ddeaguiar13:03:05

When you use an or clause in Datomic queries, all the clauses within it need to use the same set of variables

ddeaguiar13:03:43

That’s probably why you saw that error

deg13:03:51

Then, how does your example work, when one clause uses ?email and the other ?id ?

ddeaguiar13:03:00

I’m using or-join

deg13:03:39

I thought I saw that erro with or-join. Maybe I'm misremembering

ddeaguiar13:03:21

I’d recommend avoiding overly generalized queries. Queries that include predicates like [?e ?attr ?val]

deg13:03:57

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.

ddeaguiar13:03:11

I’m not sure if that ones listed there, though

ddeaguiar13:03:50

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

ddeaguiar13:03:52

And here’s more on pull in the context of queries http://docs.datomic.com/query.html#pull-expressions

deg13:03:34

Your gist, with obvious mods, works in my app. No surprise. Thanks!

deg13:03:07

I wonder what I did different yesterday, but never gonna know. Probably required the exact level of ignorance I had then.

ddeaguiar13:03:09

one thing is that if email and id are provided and each match a different user, then you’ll get two records back

deg13:03:34

Yup. In general, the semantics of what I'm asking are pretty fuzzy.

deg13:03:58

Is there some way to ensure only one is passed in? I suppose that would be done with a one-liner interceptor?

deg13:03:30

Actually, with a validator, I guess. right?

ddeaguiar13:03:18

I’d have to play around with it to say for sure

deg13:03:07

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!

ddeaguiar13:03:41

BTW, are you using the snapshot release of Vase in your app?

deg13:03:01

yes, though I've not updated it for a day or two. Why?

ddeaguiar13:03:42

Just checking, because using multiple parameters with query actions is broken on the current, stable release

ddeaguiar13:03:47

it’s fixed on master

ddeaguiar13:03:58

so I figured you were using the snapshot release

deg13:03:00

Ah, ok. thanks.

deg13:03:28

How often do you plan to release stable versions?

ddeaguiar13:03:22

That’s up to Paul and Mike. I’d need to follow up with them

deg13:03:42

Ah, sorry. I thought you were one of the leads.

ddeaguiar13:03:09

Nope, just a contributor.

deg13:03:00

Then, double thank you. I appreciate all the time and help.

mtnygard14:03:06

@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

ddeaguiar15:03:46

@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

deg18:03:29

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/).

deg18:03:05

Oh, and replying to above. Thanks for video links. I'll take a look.

ddeaguiar21:03:21

I’ve got a question for those folks who are interested in Vase.

ddeaguiar21:03:07

What would be more useful: 1. Links to critical prerequisite Pedestal and Datomic docs or 2. Just-enough Pedestal/Datomic docs to get started?

ddeaguiar21:03:17

I’m not sure what 2 would look like atm...