-
Notifications
You must be signed in to change notification settings - Fork 41
/
driver.go
41 lines (33 loc) · 1.11 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
package dbsql
import (
"context"
"database/sql"
"database/sql/driver"
"github.com/databricks/databricks-sql-go/internal/config"
_ "github.com/databricks/databricks-sql-go/logger"
)
func init() {
sql.Register("databricks", &databricksDriver{})
}
var DriverVersion = "1.6.1" // update version before each release
type databricksDriver struct{}
// Open returns a new connection to Databricks database with a DSN string.
// Use sql.Open("databricks", <dsn string>) after importing this driver package.
func (d *databricksDriver) Open(dsn string) (driver.Conn, error) {
cn, err := d.OpenConnector(dsn)
if err != nil {
return nil, err
}
return cn.Connect(context.Background())
}
// OpenConnector returns a new Connector.
// Used by sql.DB to obtain a Connector and invoke its Connect method to obtain each needed connection.
func (d *databricksDriver) OpenConnector(dsn string) (driver.Connector, error) {
ucfg, err := config.ParseDSN(dsn)
if err != nil {
return nil, err
}
return NewConnector(withUserConfig(ucfg))
}
var _ driver.Driver = (*databricksDriver)(nil)
var _ driver.DriverContext = (*databricksDriver)(nil)