Closed
Description
Not sure if i'm better asking this on the cloud sql python connector repo or here, but I'm trying to understand how to effectively call asyncpg.create_pool(...)
but make it work with the cloudsql connector.
I can create a single asyncpg-style connection using this:
from google.cloud.sql.connector import Connector
async def init():
connector = Connector(enable_iam_auth=True, loop=asyncio.get_event_loop())
conn = await connector.connect_async(
instance_connection_string="my-project:region:db-name",
driver="asyncpg",
db="postgres",
user="something@my-project.iam.gserviceaccount.com")
# do init stuff...
await conn.set_type_codec("json", encoder=json.dumps, decoder=json.loads, schema="pg_catalog")
return conn
but i'm not sure how to do a complete drop in replacement for async.create_pool
, which is what we have in the existing codebase; I'm hoping to retain the pool object as is so that the rest of the codebase doesn't need to be modified in light of switching to CloudSQL.
Thanks!
Metadata
Metadata
Assignees
Labels
No labels