forked from snowflakedb/gosnowflake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.go
66 lines (55 loc) · 1.43 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2017-2022 Snowflake Computing Inc. All rights reserved.
package gosnowflake
import (
"context"
"database/sql"
"database/sql/driver"
"os"
"sync"
)
var paramsMutex *sync.Mutex
// SnowflakeDriver is a context of Go Driver
type SnowflakeDriver struct{}
// Open creates a new connection.
func (d SnowflakeDriver) Open(dsn string) (driver.Conn, error) {
logger.Info("Open")
ctx := context.Background()
cfg, err := ParseDSN(dsn)
if err != nil {
return nil, err
}
return d.OpenWithConfig(ctx, *cfg)
}
// OpenWithConfig creates a new connection with the given Config.
func (d SnowflakeDriver) OpenWithConfig(ctx context.Context, config Config) (driver.Conn, error) {
if err := config.Validate(); err != nil {
return nil, err
}
if config.Tracing != "" {
logger.SetLogLevel(config.Tracing)
}
logger.WithContext(ctx).Info("OpenWithConfig")
sc, err := buildSnowflakeConn(ctx, config)
if err != nil {
return nil, err
}
if err = authenticateWithConfig(sc); err != nil {
return nil, err
}
sc.connectionTelemetry(&config)
sc.startHeartBeat()
sc.internal = &httpClient{sr: sc.rest}
return sc, nil
}
func runningOnGithubAction() bool {
return os.Getenv("GITHUB_ACTIONS") != ""
}
var logger = CreateDefaultLogger()
func init() {
sql.Register("sigmacomputing+gosnowflake", &SnowflakeDriver{})
logger.SetLogLevel("error")
if runningOnGithubAction() {
logger.SetLogLevel("fatal")
}
paramsMutex = &sync.Mutex{}
}