Skip to content

Rewrote internal connection implementation. #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions python/psqlpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
ReadVariant,
SingleQueryResult,
SslMode,
SynchronousCommit,
TargetSessionAttrs,
Transaction,
connect,
Expand All @@ -35,7 +34,6 @@
"ReadVariant",
"SingleQueryResult",
"SslMode",
"SynchronousCommit",
"TargetSessionAttrs",
"Transaction",
"connect",
Expand Down
34 changes: 0 additions & 34 deletions python/psqlpy/_internal/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -150,38 +150,6 @@ class SingleQueryResult:
Type that return passed function.
"""

class SynchronousCommit(Enum):
"""
Synchronous_commit option for transactions.

### Variants:
- `On`: The meaning may change based on whether you have
a synchronous standby or not.
If there is a synchronous standby,
setting the value to on will result in waiting till “remote flush”.
- `Off`: As the name indicates, the commit acknowledgment can come before
flushing the records to disk.
This is generally called as an asynchronous commit.
If the PostgreSQL instance crashes,
the last few asynchronous commits might be lost.
- `Local`: WAL records are written and flushed to local disks.
In this case, the commit will be acknowledged after the
local WAL Write and WAL flush completes.
- `RemoteWrite`: WAL records are successfully handed over to
remote instances which acknowledged back
about the write (not flush).
- `RemoteApply`: This will result in commits waiting until replies from the
current synchronous standby(s) indicate they have received
the commit record of the transaction and applied it so
that it has become visible to queries on the standby(s).
"""

On = 1
Off = 2
Local = 3
RemoteWrite = 4
RemoteApply = 5

class IsolationLevel(Enum):
"""Isolation Level for transactions."""

Expand Down Expand Up @@ -1117,15 +1085,13 @@ class Connection:
isolation_level: IsolationLevel | None = None,
read_variant: ReadVariant | None = None,
deferrable: bool | None = None,
synchronous_commit: SynchronousCommit | None = None,
) -> Transaction:
"""Create new transaction.

### Parameters:
- `isolation_level`: configure isolation level of the transaction.
- `read_variant`: configure read variant of the transaction.
- `deferrable`: configure deferrable of the transaction.
- `synchronous_commit`: configure synchronous_commit option for transaction.
"""
def cursor(
self: Self,
Expand Down
27 changes: 0 additions & 27 deletions python/tests/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
Cursor,
IsolationLevel,
ReadVariant,
SynchronousCommit,
)
from psqlpy.exceptions import (
InterfaceError,
Expand Down Expand Up @@ -362,29 +361,3 @@ async def test_execute_batch_method(psql_pool: ConnectionPool) -> None:
await transaction.execute(querystring="SELECT * FROM execute_batch2")

connection.back_to_pool()


@pytest.mark.parametrize(
"synchronous_commit",
[
SynchronousCommit.On,
SynchronousCommit.Off,
SynchronousCommit.Local,
SynchronousCommit.RemoteWrite,
SynchronousCommit.RemoteApply,
],
)
async def test_synchronous_commit(
synchronous_commit: SynchronousCommit,
psql_pool: ConnectionPool,
table_name: str,
number_database_records: int,
) -> None:
async with psql_pool.acquire() as conn, conn.transaction(
synchronous_commit=synchronous_commit,
) as trans:
res = await trans.execute(
f"SELECT * FROM {table_name}",
)

assert len(res.result()) == number_database_records
Loading
Loading