Skip to content

Add fetch_all with optional borrowed connection and Pydantic model overload - #47

Merged
aersam merged 5 commits into
mainfrom
fetch-all-helper
Oct 9, 2026
Merged

aersam merged 5 commits into
mainfrom
fetch-all-helper

Conversation

@aersam

@aersam aersam commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Moves OneSales' fetch_all into pgdevkit.db (0.13.0).

  • fetch_all(query, params=None, *, model=None, row_mapper=None, con=None, pool=None, cancel=None)
  • con= is borrowed: never committed, closed or returned to a pool. Without it a connection comes from pool= or the pool registered via set_default_pool() (single-database apps; pass pool= for several).
  • model= (Pydantic) overload, row_mapper= overload, default list[dict]. t-string queries get params-less overloads (they carry their own values).
  • query is typed LiteralString | sqlglot Expression | psycopg.sql Composable | t-string. sqlglot is imported lazily.
  • cancel: asyncio.Event aborts the running query server-side (cancel_safe() -> QueryCanceled). Cancelling the awaiting task also cancels it server-side (CancelledError propagates), drained uninterruptibly so no orphaned task/query; if the cancel request itself fails the connection is closed.
  • Skill + README updated; psycopg>=3.3 (t-strings).

Notes for reviewers

  • A sqlglot expression is only as safe as the strings it was built from (its builders parse plain strings as SQL). _render rejects exp.Command and malformed placeholder names; the docs say to pass user values as exp.Placeholder + params. A bdt lint rule for non-literal args to sqlglot builders is a follow-up (the current lint trusts sqlglot-derived text).
  • cancel= aborts whatever statement runs on the connection, so don't use it on a con shared by concurrent tasks (documented).
  • bdt lint coverage for fetch_all/fetch_one/fetch_scalar is in feat(lint): apply SQL rules to pgdevkit fetch_all/fetch_one/fetch_scalar devtools#79.
  • Live tests are requires_podman; I also ran them against a local Postgres (14 passed, stable over repeated runs).
  • OneSales migration follows once this is released.

@aersam
aersam marked this pull request as ready for review October 9, 2026 13:02
@aersam
aersam merged commit f97fed2 into main Oct 9, 2026
2 checks passed
aersam and others added 5 commits October 9, 2026 14:50
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…lation

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… cancel tests)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ams-less t-string overloads

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.

1 participant