forked from snowflakedb/gosnowflake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
connector.go
40 lines (33 loc) · 1.01 KB
/
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
// Copyright (c) 2020 Snowflake Computing Inc. All right reserved.
package gosnowflake
import (
"context"
"database/sql/driver"
)
// InternalSnowflakeDriver is the interface for an internal Snowflake driver
type InternalSnowflakeDriver interface {
Open(dsn string) (driver.Conn, error)
OpenWithConfig(ctx context.Context, config Config) (driver.Conn, error)
}
// Connector creates Driver with the specified Config
type Connector struct {
driver InternalSnowflakeDriver
cfg Config
}
// NewConnector creates a new connector with the given SnowflakeDriver and Config.
func NewConnector(driver InternalSnowflakeDriver, config Config) Connector {
return Connector{driver, config}
}
// Connect creates a new connection.
func (t Connector) Connect(ctx context.Context) (driver.Conn, error) {
cfg := t.cfg
err := fillMissingConfigParameters(&cfg)
if err != nil {
return nil, err
}
return t.driver.OpenWithConfig(ctx, cfg)
}
// Driver creates a new driver.
func (t Connector) Driver() driver.Driver {
return t.driver
}