getCloudSQLConnectionConfig returns config for Cloud SQL connector. refs: https://cloud.google.com/sql/docs/postgres/connect-connectors https://github.com/GoogleCloudPlatform/golang-samples/blob/main/cloudsql/postgres/database-sql/cloudsql.go
(ctx context.Context, conf db.ConnectionConfig)
| 274 | // https://cloud.google.com/sql/docs/postgres/connect-connectors |
| 275 | // https://github.com/GoogleCloudPlatform/golang-samples/blob/main/cloudsql/postgres/database-sql/cloudsql.go |
| 276 | func getCloudSQLConnectionConfig(ctx context.Context, conf db.ConnectionConfig) (*pgx.ConnConfig, error) { |
| 277 | d, err := util.GetGCPConnectionConfig(ctx, conf) |
| 278 | if err != nil { |
| 279 | return nil, errors.Wrap(err, "load gcp config failed") |
| 280 | } |
| 281 | |
| 282 | dsn := fmt.Sprintf("user=%s", conf.DataSource.Username) |
| 283 | config, err := pgx.ParseConfig(dsn) |
| 284 | if err != nil { |
| 285 | return nil, err |
| 286 | } |
| 287 | config.DialFunc = func(ctx context.Context, _, _ string) (net.Conn, error) { |
| 288 | return d.Dial(ctx, conf.DataSource.Host) |
| 289 | } |
| 290 | |
| 291 | config.DefaultQueryExecMode = pgx.QueryExecModeExec |
| 292 | config.StatementCacheCapacity = 0 |
| 293 | return config, nil |
| 294 | } |
| 295 | |
| 296 | // Close closes the driver. |
| 297 | func (d *Driver) Close(context.Context) error { |
no test coverage detected