-
Notifications
You must be signed in to change notification settings - Fork 32
Implement nested structs for columns and values #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement nested structs for columns and values #60
Conversation
|
Hey @ricci2511 this is awesome! I'll take a look at this later this evening and merge it if all is well. Sorry for the late response. I fixed my notifications. |
I'll be honest, I can't remember my original intention with this test. I don't know what use I think the expected outcome of this test should be |
|
@blockloop Yeah, before I looked into the code for the columns scanning I was a little confused too. I honestly didn't think too much about it and didn't want to introduce any "breaking" changes, but you're right, the In the columns method while looping through the fields the db tag check currently doesn't care about the Should we skip this step for embedded struct fields? If Im not mistaken it could be achieved by moving the nested struct traversal before the above block of code that checks for the db tag instead of after: What do you think? |
|
Once we know for sure how to handle this, I can make another commit for it and also include the fix for the coverage percentage decrease, the cause probably being the redundant |
|
Yes I think maybe the original intention was probably to prepend the struct's db tag to the subsequent fields. So for example: Even then I think that's a bit too magic for my taste and I'd probably just prefer to be explicit where the column names are ambiguous: However if the strict mode is enabled then it would require that the Address still have some kind of struct tag or the above would just return nothing: I think in strict mode we should just continue recursively when we run into a struct field and let the recursion continue searching through subsequent fields. Unless the I think if these tests passed it would make the most sense: |
|
Actually pretty much all the tests you provided are passing with my current implementation, even the ones using Finally, what if the embedded struct field has a db tag? Should we end up skipping it like I mentioned before? Example: |
|
Yes I'm thinking it should just ignore the |
|
All tests are passing and hopefully that coverage decrease is fixed too. Just one thing, not sure if it bothers you having the same recursive piece of code in two places: Maybe |
|
Okay I played with it a bit and I actually think we should just ignorestruct tags altogether since they don't really have any use. So lets change the test to: and then I refactored the code a bit to make it more clear now that we can just ignore struct tag: |
|
Looks good to me, struct tags don't make a lot of sense and just overcomplicate things. |
|
You can push them. Thanks for the contribution. I'll merge once you push and everything passes. |
Thank you for the great lib. Hopefully now everything should be ready to go 🚀 |
Closes #54.
Support for embedded structs has been added for both
scan.Columnsandscan.Valuesthrough good old recursion.I just to want to explain a little bit more in detail my changes to
scan.Values.So first of all I opted to store a slice of ints in the cache map, representing the struct field index. This allows us to directly access the corresponding struct field value while iterating over the provided
colsin the mainValuesfunction.Hopefully this image of the debugger which shows the value of
fields := loadFields(model)can make it more clear:The test that was run for the image above: