Document Session interface and Pool convenience methods#460
Open
EchoEllet wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Documents the
SessioninterfaceReason: When I first saw
Session, I assumed this might be "a PostgreSQL backend session"If that was
true, then every implementation ofSessionwould need to correspond to exactly one backend session.But
PoolimplementsSession:Poolis lazy by design and does not acquire a connection onPoolconstruction (Pool.withEndpointsis a factory method, not a static async method likeConnection.open).When running
Pool.execute()(execute()is fromSession),the pool first acquires a connection and then uses the connection.
So
Poolitself is not a session, and in this caseSessionis a capability interface that allows executing SQL statements, but not every implementation is the session itself.This changes attempts to fix this confusion by documenting what
Sessioninterface represents in this codebase (it is not necessarily a PostgreSQL physical database connection on its own).Explains why
PoolimplementsSessionandSessionExecutorThis is the other half of the fix, which attempts to explain why
PoolimplementsSessionandSessionExecutor. It seems it is a convenience API (example) that internally acquires a pooled connection via [withConnection] for each operation (exceptSessionExecutor.close()).The current Pool implementation code
Note
Keep in mind that I'm not yet knowledgeable when it comes to database drivers and complex database operation designs. So the correction might be inaccurate or misleading. In that case, the PR should be either closed or fixed.