Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

jackwotherspoon
Copy link
Collaborator

@jackwotherspoon jackwotherspoon commented Mar 24, 2025

Update README and integration tests to be more pythonic by using lambda
over intermediate getconn function.

Reduces code required and is more readable.

Instead of using getconn:

def getconn() -> pymysql.connections.Connection:
    conn: pymysql.connections.Connection = connector.connect(
        "project:region:instance",
        "pymysql",
        user="my-user",
        password="my-password",
        db="my-db-name"
    )
    return conn

pool = sqlalchemy.create_engine(
    "mysql+pymysql://",
    creator=getconn,
)

We can simplify it using a lambda:

pool = sqlalchemy.create_engine(
    "mysql+pymysql://",
    creator=lambda: connector.connect(
        "project:region:instance",
        "pymysql",
        user="my-user",
        password="my-password",
        db="my-db-name"
    ),
)

@jackwotherspoon jackwotherspoon self-assigned this Mar 24, 2025
@jackwotherspoon jackwotherspoon requested a review from a team as a code owner March 24, 2025 22:37
@jackwotherspoon jackwotherspoon changed the title chore: update tests and README to use lambda over getconn func docs: use lambda over getconn func Mar 24, 2025
@jackwotherspoon jackwotherspoon merged commit 6ecf894 into main Mar 26, 2025
15 checks passed
@jackwotherspoon jackwotherspoon deleted the update-readme branch March 26, 2025 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants