Skip to content

Support Google Cloud Run/SQL #500

Closed
Closed
@dakom

Description

@dakom

Picking up from #144 (comment)

I am using Cloud Run + Cloud SQL (postgres) and the connection string which worked with diesel does not work out of the box with sqlx. I format it like this:

//note: things in all caps, that aren't env vars, are configurable / global constants

let socket_path = std::env::var("DB_SOCKET_PATH").unwrap_or("/cloudsql".to_string());
let instance_connection = std::env::var("INSTANCE_CONNECTION_NAME").unwrap_or(MY_INSTANCE_NAME.to_string());
let full_socket_path = utf8_percent_encode(&format!("{}/{}", socket_path, instance_connection), NON_ALPHANUMERIC).to_string();

format!("postgres://{}:{}@{}/{}", DB_USER, DB_PASS, full_socket_path, DB_NAME);

Any tips appreciated! I haven't tried the PgConnectOptions approach yet

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