Skip to content

docs(RegisterConnConfig): explain alternative usage#2480

Open
AldoFusterTurpin wants to merge 1 commit intojackc:masterfrom
AldoFusterTurpin:aldo/improve_RegisterConnConfig_comment
Open

docs(RegisterConnConfig): explain alternative usage#2480
AldoFusterTurpin wants to merge 1 commit intojackc:masterfrom
AldoFusterTurpin:aldo/improve_RegisterConnConfig_comment

Conversation

@AldoFusterTurpin
Copy link

@AldoFusterTurpin AldoFusterTurpin commented Jan 14, 2026

Context
The fact that RegisterConnConfig "holds" an internal map that can grow without bound is something that could be stated explicitly.

PR changes
I believe it would be a good idea to explain an alternative for clients with many short-lived connections to many DBs, to avoid memory leaks. Being a bit more explicit and vocal in the comments about how that works will help clients to choose if they really want to use RegisterConnConfig or the alternative shared.

I placed the comment both in

  • RegisterConnConfig() (I believe this would be the perfect place as when you use a library you just check the docs from your editor and sometimes don't browse pkg.go.dev),
  • the top of the file in case people is browsing the documentation in https://pkg.go.dev/ so they can read through.

WDYT ?

Thank you!

Give an alternative for when we have clients with many short-lived
connections, to avoid memory leaks.
@AldoFusterTurpin
Copy link
Author

@jackc (Sorry for the ping) I believe this is pretty straightforward and can help new people using the module 🙂

@jackc
Copy link
Owner

jackc commented Jan 24, 2026

So it would make sense to document and emphasize the usage of stdlib.OpenDB. Whenever possible that should be preferred over RegisterConnConfig.

However, the warnings in your PR aren't exactly correct. It does not maintain a map of connections, it maintains a map of configs. You should be able to make any number of connections from a single registered conn config. Also, you can unregister them as well.

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.

2 participants