Cursors from Environment
A clearskies database cursor.
Overview
This is the base class for all cursor implementations, providing a unified interface for database operations across different backends. It manages connection setup, query execution, and SQL formatting, and supports optional port forwarding.
Port Forwarding
The port_forwarding parameter accepts an instance of a subclass of PortForwarder. This enables flexible port forwarding strategies, such as SSM, SSH with certificate, or SSH with private key. Only SSM is implemented in this repository; others can be implemented as needed.
Example: SSM Port Forwarding
from clearskies.cursors.port_forwarding.ssm import SSMPortForwarder
import clearskies
cursor = clearskies.cursors.from_environment.Mysql(
database="example",
port_forwarding=SSMPortForwarder(
instance_id="i-1234567890abcdef0",
region="eu-west-1",
),
)
cursor.execute("SELECT * FROM table")
results = cursor.fetchall()
Attributes
database: Name of the database to connect to.autocommit: Whether to automatically commit transactions.port_forwarding: Optional port forwarding configuration (PortForwarder subclass).connect_timeout: Connection timeout in seconds.table_escape_character: Character used to escape table names.column_escape_character: Character used to escape column names.value_placeholder: Placeholder character for parameter binding.