hugsql

seancorfield 2019-10-01T17:20:22.007200Z

Just looking over https://stackoverflow.com/questions/58188746/nested-namespaced-keys-in-hugsql-query and it seems like you can either have a namespaced keyword or a dotted-path (for a deep get) so the usage in the question isn't possible. Is my reading of the source correct?

seancorfield 2019-10-01T17:22:44.008100Z

I tried a variety of things and could not get a namespace-qualified keyword to work at all tho'...

seancorfield 2019-10-01T17:30:16.009Z

Given

-- :name char-by-nested-id :? :1
-- :doc Get character by nested id
select * from characters
where id = :value:model.person/id
I would have expected
user=> (ex/char-by-nested-id-sqlvec {} {:model.person/id 42})
to work but I get
Execution error (ExceptionInfo) at hugsql.core/validate-parameters! (core.clj:83).
Parameter Mismatch: :model.person/id parameter data not found.
What am I doing wrong?

curtis.summers 2019-10-01T17:32:01.009500Z

The sqlvec function params should be the first argument.

seancorfield 2019-10-01T17:32:32.010100Z

Oh. I expected it to match the signature of the non-`sqlvec` function. Silly me 🙂

seancorfield 2019-10-01T17:35:39.011Z

OK, so the SO Q's answer is that HugSQL doesn't support nested qualified keywords because . in the name portion means deep get?

seancorfield 2019-10-01T17:37:27.012900Z

The top-level key can be qualified, so where id = :value:model.person/primary.id would work for {:model.person/primary {:id 42}} (tested it and, yes, that works)

curtis.summers 2019-10-01T17:37:28.013Z

hmm...I guess that is true. Maybe deep-get really needs another syntax moving forward.

seancorfield 2019-10-01T17:38:01.013600Z

The logic merged in that PR only deals with / in the first position of the dot-separated things

seancorfield 2019-10-01T17:38:55.014500Z

And you can't have :a.b/c.d as a single keyword (even tho' it is valid in Clojure).

seancorfield 2019-10-01T17:39:47.015200Z

If it's any help, what Selmer does is use .. as an escape for the . in a keyword.

seancorfield 2019-10-01T17:40:32.016100Z

So where id = :value:model..person/primary.model..person/id would be Selmer's way of drilling down into nested qualified keys.

👍 1
seancorfield 2019-10-01T17:41:19.016500Z

Maybe you can respond to that SO question? (or I can, if you want)

curtis.summers 2019-10-01T17:42:58.017800Z

either way...it'll have to be later for me. Thanks for the selmer tip...that seems like a way forward, though I might have to put in a flag to allow the old behavior.

seancorfield 2019-10-01T18:45:31.018100Z

I gave an answer on SO https://stackoverflow.com/a/58190586/3743091

👍 1