package postgres
import "github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/postgres"
Package postgres adds a 'cloudsqlpostgres' driver to use when you want
to access a Cloud SQL Database via the go database/sql library.
It is a wrapper over the driver found at github.com/lib/pq.
To use this driver, you can look at an example in
postgres_test package in the hook_test.go file
Example shows how to use cloudsqlpostgres dialer
Code:play
Example¶
package main
import (
"database/sql"
"fmt"
"log"
"time"
_ "github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/postgres"
)
func main() {
// Note that sslmode=disable is required it does not mean that the connection
// is unencrypted. All connections via the proxy are completely encrypted.
db, err := sql.Open("cloudsqlpostgres", "host=project:region:instance user=postgres dbname=postgres password=password sslmode=disable")
if err != nil {
log.Fatal(err)
}
defer db.Close()
var now time.Time
fmt.Println(db.QueryRow("SELECT NOW()").Scan(&now))
fmt.Println(now)
}
Index ¶
Examples ¶
Types ¶
type Driver ¶
type Driver struct{}
func (*Driver) Open ¶
Deprecated: Open has been replaced by the Cloud SQL Go connector which has better support for configuring the dialer's behavior. See cloud.google.com/go/cloudsqlconn/postgres/pgxv4.RegisterDriver instead.
Source Files ¶
- Version
- v1.37.7 (latest)
- Published
- Apr 16, 2025
- Platform
- linux/amd64
- Imports
- 8 packages
- Last checked
- 2 months ago –
Tools for package owners.