Skip to content
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

Perform repo initialization via array of structs #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

antifuchs
Copy link

As @nelhage and I discussed out-of-band earlier today, using a map[string]**sqlx.NamedStmt works well until you have to put two of the same SQL statement into the repository: Suddenly, one slot stops getting initialized. The change in this PR alters the initialization loop to use an array of structs, which eliminates the uniqueness requirement and should give us all some peace of mind (:

Slight downside is that there's a little bit more line noise and that what was nicely lined-up key/value pairs before no longer lines up. But I believe the gain in correctness is worth it.

The method of initializing the repo via a map[string]**sqlx.NamedStmt
usually works well, until you hit the case where two identical SQL
statements should be registered somewhere (this probably happens more in
tests than it does in real life, but it can plausibly happen).

Making the initialization loop operate on an array of structures
sidesteps this problem quite nicely: With this change, every SQL
statement can get registered on a NamedStmt field, no matter what its
shape or how similar it is to other statements on the repository.
@antifuchs
Copy link
Author

It occurs to me that you could get the exact benefits of this change with the lining-up nature of key/value things in maps by just flipping the map type from map[string]**sqlx.NamedStmt to map[**sqlx.NamedStmt]string - that'd eliminate all uniqueness problems and still be as readable as before. Let me know which version you prefer (:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant