Really I'd like to add some helpers that handle the whole "run query, defer
Rows.Close(), read rows into slice of structs" process. I've got some example
code here:
https://github.com/rawlinp/trafficcontrol/compare/master...rawlinp:add-get-rows-helpers#diff-885017a84a9274d9fe8d218c5489c9f9R105
Right now we're kind of all over the place in terms of sql vs sqlx, Query vs
Queryx vs NamedQuery, Scan vs StructScan, etc. The general process is the same
in a lot of places; it's just the chosen methods for running the query and
scanning that seem the most customized. Having a standardized set of helper
functions for querying DB rows into slices of structs would allow us to enforce
things better that are easy to forget about, like `defer rows.Close()` and
checking `rows.Err()` after the `for rows.Next() {...}` block. The latter we
basically aren't doing anywhere, but the API reference states it's necessary
because `Next()` can return false with an error (which we aren't checking).
I'm not necessarily saying that should be done in this PR, but I'm curious what
you think of the idea. Maybe a lot of existing queries are too customized to
really benefit from helper functions like that, but maybe reworking some of
that would be a good thing.
[ Full content available at: https://github.com/apache/trafficcontrol/pull/2862
]
This message was relayed via gitbox.apache.org for [email protected]