pgx icon indicating copy to clipboard operation
pgx copied to clipboard

Provide method to retrieve parameterStatuses keys from

Open devhawk opened this issue 1 year ago • 3 comments

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.

devhawk avatar Nov 29 '23 01:11 devhawk

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.

  1. 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.
  2. Clone the map.
  3. Return an array of keys.

I kind of lean toward the first option as it avoids any allocations.

jackc avatar Dec 02 '23 14:12 jackc

Call back based iterator would also work (https://blog.kowalczyk.info/article/1Bkr/3-ways-to-iterate-in-go.html)

devhawk avatar Dec 07 '23 01:12 devhawk

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.

jackc avatar Dec 09 '23 18:12 jackc