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

Method Open

backend/plugin/db/spanner/spanner.go:65–101  ·  view source on GitHub ↗

Open opens a Spanner 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

63// Open opens a Spanner driver. It must connect to a specific database.
64// If database isn't provided, part of the driver cannot function.
65func (d *Driver) Open(ctx context.Context, _ storepb.Engine, config db.ConnectionConfig) (db.Driver, error) {
66 if config.DataSource.Host == "" {
67 return nil, errors.New("host cannot be empty")
68 }
69 d.config = config
70 d.connCtx = config.ConnectionContext
71
72 var o []option.ClientOption
73 if gcpCredential := config.DataSource.GetGcpCredential(); gcpCredential != nil {
74 credOption, err := util.GCPCredentialOption([]byte(gcpCredential.Content))
75 if err != nil {
76 return nil, err
77 }
78 o = append(o, credOption)
79 }
80 if config.ConnectionContext.DatabaseName != "" {
81 d.databaseName = config.ConnectionContext.DatabaseName
82 dsn := getDSN(d.config.DataSource.Host, config.ConnectionContext.DatabaseName)
83 client, err := spanner.NewClient(
84 ctx,
85 dsn,
86 o...,
87 )
88 if err != nil {
89 return nil, err
90 }
91 d.client = client
92 }
93
94 dbClient, err := spannerdb.NewDatabaseAdminClient(ctx, o...)
95 if err != nil {
96 return nil, err
97 }
98
99 d.dbClient = dbClient
100 return d, nil
101}
102
103// Close closes the driver.
104func (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 3

GCPCredentialOptionFunction · 0.92
getDSNFunction · 0.85
GetGcpCredentialMethod · 0.45

Tested by

no test coverage detected