Postgresql
A clearskies PostgreSQL cursor.
Overview
This class provides a PostgreSQL cursor implementation with support for connection configuration, port forwarding, and SQL formatting.
Configuration
The following parameters are available (with their default values):
hostname: Hostname of the PostgreSQL server (localhost)username: Username for authentication (root)password: Password for authentication ("")database: Name of the database (example)port: Port number (defaults to 5432 if not specified)cert_path: Path to SSL certificate (optional)autocommit: Whether to autocommit transactions (True)connect_timeout: Connection timeout in seconds (2)port_forwarding: Optional port forwarding configuration (see below)
Port Forwarding
The port_forwarding parameter accepts an instance of a subclass of PortForwarder, enabling SSM or SSH-based port forwarding if required.
Example
from clearskies.cursors.port_forwarding.ssm import SSMPortForwarder
import clearskies
cursor = clearskies.cursors.Postgresql(
hostname="db.internal",
username="admin",
password="secret",
database="mydb",
port_forwarding=SSMPortForwarder(
instance_id="i-1234567890abcdef0",
region="eu-west-1",
),
)
cursor.execute("SELECT * FROM users")
results = cursor.fetchall()
hostname
Optional
Hostname of the PostgreSQL server.
username
Optional
Username for authentication.
password
Optional
Password for authentication.
database
Optional
Name of the database to connect to.
autocommit
Optional
Whether to automatically commit transactions.
connect_timeout
Optional
Connection timeout in seconds.
port
Optional
Port number for the PostgreSQL server (defaults to 5432 if not specified).
cert_path
Optional
Path to SSL certificate (optional).
port_forwarding
Optional