Skip to content

Expose get_db_connection publicly#32

Merged
marcelofern merged 1 commit into
mainfrom
make_get_db_connection_public
May 15, 2025
Merged

Expose get_db_connection publicly#32
marcelofern merged 1 commit into
mainfrom
make_get_db_connection_public

Conversation

@marcelofern

Copy link
Copy Markdown
Collaborator

Prior to this change, a Psycopack user interfacing with the Python API would have to call Psycopack in such way:

  with _conn.get_db_connection(DATABASE_URL) as conn:
      with conn.cursor() as cur:
          repack = Repack(
              conn=conn,
              cur=cur,
              ...
          )
          repack.full()

This isn't ideal because the _conn module is private.

There is also no option for the user to directly get their connection and cursor from psycopg2 or psycopg (3), unless they don't care about type annotations (in which case they already can).

This commit exposes get_db_connection publicly so that users can get type-annotated cursors and connections.

Prior to this change, a Psycopack user interfacing with the Python API
would have to call Psycopack in such way:

  with _conn.get_db_connection(DATABASE_URL) as conn:
      with conn.cursor() as cur:
          repack = Repack(
              conn=conn,
              cur=cur,
              ...
          )
          repack.full()

This isn't ideal because the _conn module is private.

There is also no option for the user to directly get their connection
and cursor from psycopg2 or psycopg (3), unless they don't care about
type annotations (in which case they already can).

This commit exposes get_db_connection publicly so that users can get
type-annotated cursors and connections.
@marcelofern marcelofern requested a review from a team May 15, 2025 00:45
@github-actions

Copy link
Copy Markdown

Coverage Report Results

Name Stmts Miss Branch BrPart Cover
src/psycopack/__init__.py 5 0 0 0 100%
src/psycopack/_commands.py 109 0 8 0 100%
src/psycopack/_conn.py 5 0 0 0 100%
src/psycopack/_const.py 2 0 0 0 100%
src/psycopack/_cur.py 16 0 0 0 100%
src/psycopack/_identifiers.py 12 0 2 0 100%
src/psycopack/_introspect.py 155 0 12 0 100%
src/psycopack/_logging.py 4 0 0 0 100%
src/psycopack/_psycopg.py 5 0 0 0 100%
src/psycopack/_repack.py 343 0 114 0 100%
src/psycopack/_tracker.py 165 0 36 0 100%
tests/conftest.py 18 0 0 0 100%
tests/factories.py 33 0 4 0 100%
tests/test_cur.py 20 0 2 0 100%
tests/test_fixtures.py 5 0 0 0 100%
tests/test_package.py 3 0 0 0 100%
tests/test_repack.py 659 0 0 0 100%
TOTAL 1559 0 178 0 100%

1 empty file skipped.

@marcelofern marcelofern marked this pull request as ready for review May 15, 2025 00:47
@marcelofern marcelofern merged commit 9f8fa71 into main May 15, 2025
9 checks passed
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