pgx
pgx copied to clipboard
Provide method to retrieve parameterStatuses keys from
PgConn struct has a private parameterStatuses map field. The PgConn.ParameterStatus method returns the value of a specified key from that map. As far as I can tell, there is no mechanism to retrieve the set of keys in the map.
PgConn should expose either a clone of the parameterStatuses field (generated via maps.Clone maybe?) or an array of
the parameterStatuses keys that the caller can then use to call the existing ParameterStatus with.
I agree this would be useful. This might be part of #1803. Otherwise, a new method could be added.
I see 3 options for that method.
- Return the parameter statuses map directly. This means we can't prevent the caller from mutating it. But it is fairly common in Go to document that a return value must not be changed.
- Clone the map.
- Return an array of keys.
I kind of lean toward the first option as it avoids any allocations.
Call back based iterator would also work (https://blog.kowalczyk.info/article/1Bkr/3-ways-to-iterate-in-go.html)
Yeah, an iterator would be possible. Though maybe overkill. Hmm... actually if that was done it would be best to use the new https://github.com/golang/go/issues/61405 Go iteration construct (though that would mean delaying the feature for at least a year).
Though I think I still lean toward exposing the map directly.