Back to Go Cloud

MySQL/PostgreSQL

internal/website/content/howto/sql/_index.md

0.45.02.4 KB
Original Source

Connecting to Cloud providers' hosted database services requires additional steps to ensure the security of the connection. For example, each of GCP, AWS and Azure require the use of custom certificate authorities to be configured in the client. GCP requires a custom proxy with authentication credentials. The Go CDK makes opening these connections easier while still using the standard *sql.DB type.

<!--more-->

Local or On-Premise {#local}

The Go CDK uses the same [URL opener pattern][] as seen in other Go CDK APIs. It differs from the standard library's sql.Open in that it automatically instruments the connection with OpenCensus metrics.

The portable function for MySQL is mysql.Open:

{{< goexample "gocloud.dev/mysql.ExampleOpen" >}}

And the portable function for PostgreSQL is postgres.Open:

{{< goexample "gocloud.dev/postgres.ExampleOpen" >}}

[URL opener pattern]: {{< ref "/concepts/urls.md" >}}

GCP {#gcp}

Users of GCP Cloud SQL for MySQL should import the gocloud.dev/mysql/gcpmysql package:

{{< goexample "gocloud.dev/mysql/gcpmysql.Example" >}}

Users of GCP Cloud SQL for PostgreSQL should import the gocloud.dev/postgres/gcppostgres package:

{{< goexample "gocloud.dev/postgres/gcppostgres.Example" >}}

AWS {#aws}

Users of AWS RDS for MySQL should import the gocloud.dev/mysql/awsmysql package:

{{< goexample "gocloud.dev/mysql/awsmysql.Example" >}}

Users of AWS RDS for PostgreSQL should import the gocloud.dev/postgres/awspostgres package:

{{< goexample "gocloud.dev/postgres/awspostgres.Example" >}}

Azure {#azure}

Users of Azure Database for MySQL should import the gocloud.dev/mysql/azuremysql package:

{{< goexample "gocloud.dev/mysql/azuremysql.Example" >}}

Other Usage Samples