Conversation
mjball
left a comment
There was a problem hiding this comment.
I love it. Thank you for adding this!
I'm curious if people think this will cause confusion since @BindWithRosetta Collection is already a valid usage?
This is an interesting point... do you think it would be feasible to hook up this new behavior into the existing @BindWithRosetta binding machinery iff the value refers to a list-valued parameter? I think it might be doable with Binding#findForName() (and maybe SqlArrayTypes?) but not 100% sure.
I'm also not entirely if that's a thing we'd want to do, in case existing code is relying on the current behavior. Though... what is the current behavior of @BindWithRosetta("foos") Collection<Foo> + WHERE foos IN (<foos>)?
| } else { | ||
| List<Object> list = new ArrayList<>(node.size()); | ||
| RosettaBinder.INSTANCE.bindList((ArrayNode) node, bindList.field(), list::add); | ||
| stmt.bindList(name, list); |
There was a problem hiding this comment.
i think there's an override of bindList that takes EmptyHandling. Could you use that instead of the above switch?
There was a problem hiding this comment.
🤔 I see it in the docs but I don't see it in IntelliJ, wonder if it was added in a later version of jdbi3?
|
Would this change mean the recommended way to bind collections will now be |
Using the tests I wrote as an example, a function like this @SqlQuery("SELECT * FROM test_list_table WHERE value IN (<values>)")
List<TestListObject> getWithValueWithRosetta(@BindWithRosetta List<TestEnum> values);Will transform the list into { "it": [1] }which results in a named binding ("it") to a
I've tried a few different ways of doing this but haven't come up with something workable yet. The
My understanding is that the only common case where This is, however, exactly the type of confusion that I'm worried about. The jdbi team seemed to think that having separate annotations was worth it, but rosetta has different history/expected usage ( Another unrelated thought: there is |
|
Anyone else have thoughts on this? |
| } | ||
| } | ||
|
|
||
| if (value.isObject() ) { |
There was a problem hiding this comment.
Should we disallow arrays as well? We could also disallow null nodes, though I'm not sure if it's possible for that to make it here.
There was a problem hiding this comment.
Hmm, I think disallowing array nodes makes sense here, but I'm not sure we'd want to disallow null nodes, since that's what an optional field would be mapped to. We could do something like !value.isValueNode() which would disallow object, array and missing nodes.
RosettaJdbi3/src/test/java/com/hubspot/rosetta/jdbi3/TestEnum.java
Outdated
Show resolved
Hide resolved
RosettaJdbi3/src/test/java/com/hubspot/rosetta/jdbi3/TestListObject.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Should we have more tests for the error cases?
|
Any other thoughts here? |
RosettaCore/src/main/java/com/hubspot/rosetta/RosettaBinder.java
Outdated
Show resolved
Hide resolved
RosettaCore/src/main/java/com/hubspot/rosetta/RosettaBinder.java
Outdated
Show resolved
Hide resolved
Co-authored-by: stevie400 <3606665+stevie400@users.noreply.github.com>
|
LGTM |
This was a fun little side project. Also I added support for selecting a subfield from a list of objects since that's something I've wanted several times in the past
I'm curious if people think this will cause confusion since
@BindWithRosetta Collection<Thing>is already a valid usage?@jhaber @mjball @stevie400 @Xcelled