MCPcopy Create free account
hub / github.com/bytebase/bytebase / getCloudSQLConnectionConfig

Function getCloudSQLConnectionConfig

backend/plugin/db/pg/pg.go:276–294  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
276func 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.
297func (d *Driver) Close(context.Context) error {

Callers 1

OpenMethod · 0.85

Calls 2

GetGCPConnectionConfigFunction · 0.92
DialMethod · 0.65

Tested by

no test coverage detected