-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdriver.go
52 lines (45 loc) · 1.15 KB
/
driver.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
48
49
50
51
52
package bigquery
import (
"context"
"database/sql"
"database/sql/driver"
"google.golang.org/api/option"
)
// Driver is exported to make the driver directly accessible.
// In general the driver is used via the database/sql package.
type Driver struct{}
// Open new Connection.
// See https://github.com/viant/bigquery#dsn-data-source-name for how
// the DSN string is formatted
func (d Driver) Open(dsn string) (driver.Conn, error) {
cfg, err := ParseDSN(dsn)
if err != nil {
return nil, err
}
c := &connector{
cfg: cfg,
}
return c.Connect(context.Background())
}
//SetGCPClientOptions sets global gcp options
func (d *Driver) SetGCPClientOptions(options ...option.ClientOption) {
SetOptions(options...)
}
func init() {
sql.Register("bigquery", &Driver{})
}
// NewConnector returns new driver.Connector.
func NewConnector(cfg *Config) (driver.Connector, error) {
return &connector{cfg: cfg}, nil
}
// OpenConnector implements driver.DriverContext.
func (d Driver) OpenConnector(dsn string) (driver.Connector, error) {
cfg, err := ParseDSN(dsn)
if err != nil {
return nil, err
}
return &connector{
cfg: cfg,
options: globalOptions,
}, nil
}