Use polypheny.connect() to obtain a Connection. A connection holds a Prism session and the transaction shared by its cursors.
| Method | Behavior |
|---|---|
cursor() |
Creates and returns a Cursor registered with the connection. Each cursor holds its own current result. |
commit() |
Commits the current transaction. |
rollback() |
Rolls back pending work in the current transaction. |
close() |
Closes all cursors, rolls back pending work, and disconnects. Calls after closure return without effect. |
Auto-commit starts disabled. DDL commits automatically, including earlier changes in the same transaction. Any pending DML is rolled back when you close the connection, so call commit() before closing if you want to keep it. The connector raises polypheny.ProgrammingError when you call cursor(), commit() or rollback() on a closed connection.
Use try/finally or contextlib.closing to release resources. closing calls close() and leaves commit and rollback decisions to the application.
import os
from contextlib import closing
import polypheny
with closing(polypheny.connect(
(os.getenv("POLYPHENY_HOST", "127.0.0.1"), int(os.getenv("POLYPHENY_PORT", "20590"))),
username=os.getenv("POLYPHENY_USER", "pa"),
password=os.getenv("POLYPHENY_PASSWORD", ""),
transport="plain",
)) as connection:
with closing(connection.cursor()) as cursor:
cursor.execute("SELECT 1")
print(cursor.fetchone())
connection.commit()
See Getting Started for an example that commits and rolls back inserts. Use a connection and its cursors on one thread. The connector’s internal transport and cursor bookkeeping can change between releases.