Repository navigation
Conversation
Contributor
Author
|
This is a bigger change. In theory it should be worthwhile but I'll need to review it before it's ready to consider. |
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.
Problem and behavior
PR #87 stops raw PostgreSQL connections from creating a new named statement for every parameterized call. This draft adds an opt-in
ManagedDbConnfor callers that own a stable libpq session and want bounded prepared-plan reuse. It prepares each distinct SQL string once on that session, up to 64 plans by default. Additional distinct SQL executes directly.maxPlans = 0disables caching.The connection is move-only under ARC/ORC. Scope exit or explicit
close()releases its session and plans;reset()reconnects and invalidates the cache. Inlinequery:/query(T):and generatedcreateProc/createItercalls accept the owned connection. Single-row andINSERT ... RETURNINGpaths now compile and preserve the existing raw PostgreSQL error behavior. A closed managed connection raises a clearDbError.Safety contract
Stacked on #87: review the managed-connection commits on top of that PR until it merges. Raw
DbConncalls retain their API and, through #87, use direct execution. The owned connection must be used from one thread at a time with a direct PostgreSQL connection or session pooler. Transaction pooling cannot preserve session-local plans.borrowRawis for temporary interop; callers must not finish or reset that borrowed handle.A missing plan, schema-induced plan error, or connection failure is returned to the caller without replaying the query, since side effects may be uncertain. After a missing or stale plan, that session switches to direct execution. The caller can explicitly reset and retry if appropriate.
Validation
nim testpassed (SQLite and compile-time suites).nim test_postgrespassed against PostgreSQL 14, including the managed-copy compile-fail check.tryQuery, andINSERT ... RETURNINGsuccess/failure.This remains a draft for API and lifecycle review; do not merge it before #87.