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

Function getCloudSQLConnection

backend/plugin/db/mysql/mysql.go:254–267  ·  view source on GitHub ↗
(ctx context.Context, connCfg db.ConnectionConfig)

Source from the content-addressed store, hash-verified

252}
253
254func getCloudSQLConnection(ctx context.Context, connCfg db.ConnectionConfig) (string, error) {
255 d, err := util.GetGCPConnectionConfig(ctx, connCfg)
256 if err != nil {
257 return "", errors.Wrap(err, "load gcp config failed")
258 }
259
260 mysql.RegisterDialContext("cloudsqlconn",
261 func(ctx context.Context, _ string) (net.Conn, error) {
262 return d.Dial(ctx, connCfg.DataSource.Host)
263 })
264
265 return fmt.Sprintf("%s:empty@cloudsqlconn(localhost:3306)/%s?parseTime=true&multiStatements=true&maxAllowedPacket=0",
266 connCfg.DataSource.Username, connCfg.ConnectionContext.DatabaseName), nil
267}
268
269// Close closes the driver.
270func (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