Skip to content

Commit eba5aaa

Browse files
authored
docs: restore asyncpg pool usage in README (#538)
This is a follow-on to #525.
1 parent 327e773 commit eba5aaa

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,44 @@ with Connector() as connector:
102102
print(result)
103103
```
104104

105+
### Async (asyncpg)
106+
107+
**Install:**
108+
```sh
109+
pip install "google-cloud-alloydb-connector[asyncpg]"
110+
```
111+
112+
**Connect:**
113+
114+
```python
115+
import asyncio
116+
import asyncpg
117+
from google.cloud.alloydbconnector import AsyncConnector
118+
119+
INSTANCE_URI = "projects/MY_PROJECT/locations/MY_REGION/clusters/MY_CLUSTER/instances/MY_INSTANCE"
120+
121+
async def main():
122+
async with AsyncConnector() as connector:
123+
pool = await asyncpg.create_pool(
124+
INSTANCE_URI,
125+
connect=lambda instance_connection_name, **kwargs: connector.connect(
126+
instance_connection_name,
127+
"asyncpg",
128+
user="my-user",
129+
password="my-password",
130+
db="my-db",
131+
),
132+
)
133+
134+
async with pool.acquire() as conn:
135+
result = await conn.fetchval("SELECT NOW()")
136+
print(result)
137+
138+
await pool.close()
139+
140+
asyncio.run(main())
141+
```
142+
105143
### Async (asyncpg + SQLAlchemy)
106144

107145
**Install:**

0 commit comments

Comments
 (0)