-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnector.go
47 lines (39 loc) · 916 Bytes
/
connector.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package bigquery
import (
"context"
"database/sql/driver"
"cloud.google.com/go/bigquery"
)
var (
_ driver.Connector = (*connector)(nil)
)
type connector struct {
config Config
}
func NewConnector(config Config) driver.Connector {
return &connector{
config: config,
}
}
func (c *connector) Connect(ctx context.Context) (driver.Conn, error) {
// NOTE: We can't pass the provided context to NewClient, or it will cease
// working when the context is cancelled (whereas the context provided to
// this function should only control the lifetime of the connection event
// itself).
client, err := bigquery.NewClient(
context.Background(),
c.config.ProjectID,
c.config.Options...,
)
if err != nil {
return nil, err
}
client.Location = c.config.Location
return &conn{
client: client,
config: c.config,
}, nil
}
func (c *connector) Driver() driver.Driver {
return &bigQueryDriver{}
}