-
Notifications
You must be signed in to change notification settings - Fork 4
/
driver.go
49 lines (41 loc) · 1.32 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
// mysqlx - MySQL driver for Go's database/sql package and MySQL X Protocol.
// Copyright (c) 2017-2018 Alexey Palazhchenko
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package mysqlx
import (
"context"
"database/sql"
"database/sql/driver"
)
type driverType struct{}
// Driver implements database/sql/driver.Driver and database/sql/driver.DriverContext interfaces.
// It has no internal state.
var Driver driverType
// Open returns a new connection to the database. See README for data source format.
// The returned connection must be used only by one goroutine at a time.
func (d driverType) Open(dataSource string) (driver.Conn, error) {
connector, err := d.OpenConnector(dataSource)
if err != nil {
return nil, err
}
return open(context.Background(), connector.(*Connector))
}
// OpenConnector returns Connector for a given data source.
func (d driverType) OpenConnector(dataSource string) (driver.Connector, error) {
connector, err := ParseDataSource(dataSource)
if err != nil {
return nil, err
}
return connector, nil
}
func init() {
sql.Register("mysqlx", Driver)
}
// check interfaces
var (
_ driver.Driver = Driver
_ driver.DriverContext = Driver
)