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)
| 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. |
| 50 | func (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. |
| 75 | func (d *Driver) Close(_ context.Context) error { |
nothing calls this directly
no test coverage detected