GoogleCloudPlatform / GoogleCloudPlatform/cloud-sql-python-connector

Consider `AsyncConnector` object for async interface

Offen
#687 2 Kommentare 2 Reaktionen 1 zugewiesene Person Zugewiesen an @kgala2 Auf GitHub ansehen
priority: p2 type: feature request
Vorherrschende Sprache
Python
Sterne
344
Forks
89
Ø Merge
5 Std. 33 Min.
Gemergte PRs (30 T.)
2

Beschreibung

### 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

```Python
# 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_

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.