File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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:**
You can’t perform that action at this time.
0 commit comments