Skip to content

Configure a custom dialer #3909

Closed
Closed
@tobiassjosten

Description

@tobiassjosten

I'm using GoogleCloudPlatform/cloud-sql-go-connector for my application, to connect to Cloud SQL both locally and from Cloud Run. For the driver, I'm using pgx (pgxpool), with a regular DSN string (user=asdf password=qwer dbname=zxcv sslmode=disabled) and the connection happens through a custom dialer:

config, err := pgxpool.ParseConfig(os.Getenv("CLOUD_SQL_DSN"))
if err != nil {
	log.Fatalf("Unable to parse config: %v\n", err)
}

d, err := cloudsqlconn.NewDialer(ctx)
if err != nil {
	log.Fatalf("Unable to create dialer: %v\n", err)
}

config.ConnConfig.DialFunc = func(ctx context.Context, _ string, instance string) (net.Conn, error) {
	return d.Dial(ctx, os.Getenv("CLOUD_SQL_ICN"))
}

pool, err := pgxpool.NewWithConfig(ctx, config)
if err != nil {
	log.Fatalf("Unable to connect to database: %v\n", err)
}

Is there a way to achieve this with sqlc? I've looked around the code but can't find a way to "hook in" to the configuration and set my custom dialer.

Any help or pointers would be appreciated!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions