Skip to content

GCP CloudSQL Connector with asyncpg Pool #1148

Closed
@d1manson

Description

@d1manson

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions