Skip to content

Support for Cloud SQL host within the dsn #419

Closed
@gvbgduh

Description

@gvbgduh

Hi,

I'm trying to use asyncpg to connect to Google Cloud SQL together with [databases](https://github.com/encode/databases/), alembic and sometimes sqlalchemy. It's quite convenient to have one database url that can be used in different cases.

But there's one problem as the Cloud SQL host is in the format /cloudsql/<project>:<region>:<db_instance>.

Unfortunately, it breaks the parsing around https://github.com/MagicStack/asyncpg/blob/master/asyncpg/connect_utils.py#L182, so the port and host cannot be distinguished unless host is explicitly passed as kwarg.

Would it be possible to consider adding the support for such a case?

Naive solution seems to be to use rpartition there, so the url
'postgresql://USER:PWD@/DB?host=/cloudsql/::<db_instance>:5432'
can be used, but I can investigate this one more thorough if seems like a reasonable case.

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