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

Method Open

backend/plugin/db/bigquery/bigquery.go:50–72  ·  view source on GitHub ↗

Open opens a BigQuery driver. It must connect to a specific database. If database isn't provided, part of the driver cannot function.

(ctx context.Context, _ storepb.Engine, config db.ConnectionConfig)

Source from the content-addressed store, hash-verified

48// Open opens a BigQuery driver. It must connect to a specific database.
49// If database isn't provided, part of the driver cannot function.
50func (d *Driver) Open(ctx context.Context, _ storepb.Engine, config db.ConnectionConfig) (db.Driver, error) {
51 if config.DataSource.Host == "" {
52 return nil, errors.New("host cannot be empty")
53 }
54 d.config = config
55 d.connCtx = config.ConnectionContext
56 d.databaseName = config.ConnectionContext.DatabaseName
57
58 var o []option.ClientOption
59 if gcpCredential := config.DataSource.GetGcpCredential(); gcpCredential != nil {
60 credOption, err := util.GCPCredentialOption([]byte(gcpCredential.Content))
61 if err != nil {
62 return nil, err
63 }
64 o = append(o, credOption)
65 }
66 client, err := bigquery.NewClient(ctx, config.DataSource.Host, o...)
67 if err != nil {
68 return nil, err
69 }
70 d.client = client
71 return d, nil
72}
73
74// Close closes the driver.
75func (d *Driver) Close(_ context.Context) error {

Callers

nothing calls this directly

Implementers 15

MockDriverbackend/plugin/advisor/utils_for_tests
Driverbackend/plugin/db/bigquery/bigquery.go
Driverbackend/plugin/db/mongodb/mongodb.go
Driverbackend/plugin/db/trino/trino.go
Driverbackend/plugin/db/redshift/redshift.go
Driverbackend/plugin/db/oracle/oracle.go
Driverbackend/plugin/db/dynamodb/dynamodb.go
Driverbackend/plugin/db/cosmosdb/cosmosdb.go
Driverbackend/plugin/db/spanner/spanner.go
Driverbackend/plugin/db/mssql/mssql.go
Driverbackend/plugin/db/mysql/mysql.go
Driverbackend/plugin/db/pg/pg.go

Calls 2

GCPCredentialOptionFunction · 0.92
GetGcpCredentialMethod · 0.45

Tested by

no test coverage detected