Skip to content

docs: use lambda over getconn func #1251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 26, 2025
Merged

docs: use lambda over getconn func #1251

merged 2 commits into from
Mar 26, 2025

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