Skip to main content
A class for holding the properties of a database connection. The class is usually created in the pyconfigs/connections.py file. This class can be imported from the squirrels.connections or the squirrels module.

Constructor

Creates a ConnectionProperties object.
def __init__(
    self, *, type: ConnectionTypeEnum = ConnectionTypeEnum.SQLALCHEMY, 
    uri: str, label: str | None = None, 
    sa_create_engine_args: dict[str, Any] = {}
) -> None:

Examples

Below is an example of a pyconfigs/connections.py file that uses ConnectionProperties to define a SQLite database connection.
from typing import Any
from squirrels import arguments as args, connections as cn


def main(connections: dict[str, cn.ConnectionProperties | Any], sqrl: args.ConnectionsArgs) -> None:
    """
    Define sqlalchemy engines by adding them to the "connections" dictionary
    """
    ## SQLAlchemy URL for a connection engine
    conn_str: str = "sqlite://{project_path}/path/to/database.db"

    ## Assigning names to connection engines
    connections["default"] = cn.ConnectionProperties(
        label="SQLite Database", 
        type=cn.ConnectionTypeEnum.SQLALCHEMY, 
        uri=conn_str.format(project_path=sqrl.project_path)
    )
The following are additional examples of creating ConnectionProperties objects.

SQLAlchemy connection with engine arguments

# Connection with custom SQLAlchemy engine settings
postgres_conn = ConnectionProperties(
    uri="postgresql://user:password@localhost:5432/mydb",
    label="Production Database",
    sa_create_engine_args={
        "pool_size": 10,
        "pool_pre_ping": True
    }
)

DuckDB connection

# DuckDB native connection
duckdb_conn = ConnectionProperties(
    type=ConnectionTypeEnum.DUCKDB,
    uri="/path/to/database.duckdb",
    label="DuckDB database"
)

# You can also connect to other databases using DuckDB
# such as PostgreSQL, MySQL, and SQLite.
postgres_conn = ConnectionProperties(
    type=ConnectionTypeEnum.DUCKDB,
    uri="postgresql://username@hostname/dbname",
    label="PostgreSQL database"
)

sqlite_conn = ConnectionProperties(
    type=ConnectionTypeEnum.DUCKDB,
    uri="sqlite:/path/to/database.db",
    label="SQLite database"
)

ADBC connection

# Arrow Database Connectivity connection
adbc_conn = ConnectionProperties(
    type=ConnectionTypeEnum.ADBC,
    uri="postgresql://user:password@localhost:5432/mydb",
    label="High Performance ADBC"
)

ConnectorX connection

# Fast data loading with ConnectorX
cx_conn = ConnectionProperties(
    type=ConnectionTypeEnum.CONNECTORX,
    uri="postgresql://user:password@localhost:5432/mydb",
    label="Fast Loading Connection"
)