Skip to content
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

Consider AsyncConnector object for async interface #687

Open
jackwotherspoon opened this issue Mar 30, 2023 · 0 comments
Open

Consider AsyncConnector object for async interface #687

jackwotherspoon opened this issue Mar 30, 2023 · 0 comments
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@jackwotherspoon
Copy link
Collaborator

jackwotherspoon commented Mar 30, 2023

Feature Description

Currently the Connector object is the main entrypoint for both synchronous and async driver implementations.

The synchronous drivers are called via connector.connect while the async drivers via connector.connect_async with the synchronous version basically just being a simple wrapper around the async method.

This issue is to keep an eye on considering moving the async drivers to a separate object and entrypoint of AsyncConnector.

This would allow for clear distinctions between the two and give flexibility in the interfaces moving forward.

Sample code

# current implementation
async def main():
    # get current running event loop to be used with Connector
    loop = asyncio.get_running_loop()
    # intialize Connector object as async context manager
    async with Connector(loop=loop) as connector:
        # create connection to Cloud SQL database
        conn: asyncpg.Connection = await connector.connect_async(
            "project:region:instance",  # Cloud SQL instance connection name
            "asyncpg",
            user="my-user",
            password="my-password",
            db="my-db-name"
            # ... additional database driver args
        )

# new AsyncConnector object
async def main():
    async with AsyncConnector() as connector:
        # create connection to Cloud SQL database
        conn: asyncpg.Connection = await connector.connect(
            "project:region:instance",  # Cloud SQL instance connection name
            "asyncpg",
            user="my-user",
            password="my-password",
            db="my-db-name"
            # ... additional database driver args
        )

Alternatives Considered

No response

Additional Details

No response

@jackwotherspoon jackwotherspoon added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. labels Mar 30, 2023
@jackwotherspoon jackwotherspoon added priority: p2 Moderately-important priority. Fix may not be included in next release. and removed priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. labels May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

1 participant