Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion go/vt/vitessdriver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func OpenWithConfiguration(c Configuration) (*sql.DB, error) {
vtgateconn.RegisterDialer(c.Protocol, grpcvtgateconn.DialWithOpts(context.TODO(), c.GRPCDialOptions...))
}

return sql.Open("vitess", json)
return sql.Open(c.DriverName, json)
}

type drv struct {
Expand Down Expand Up @@ -160,6 +160,12 @@ type Configuration struct {
//
// Default: none
GRPCDialOptions []grpc.DialOption `json:"-"`

// Driver is the name registered with the database/sql package. This override
// is here in case you have wrapped the driver for stats or other interceptors.
//
// Default: "vitess"
DriverName string `json:"-"`
}

// toJSON converts Configuration to the JSON string which is required by the
Expand All @@ -179,6 +185,10 @@ func (c *Configuration) setDefaults() {
if c.Protocol == "" {
c.Protocol = "grpc"
}

if c.DriverName == "" {
c.DriverName = "vitess"
}
}

type conn struct {
Expand Down
14 changes: 9 additions & 5 deletions go/vt/vitessdriver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ func TestOpen(t *testing.T) {
connStr: fmt.Sprintf(`{"address": "%s", "target": "@replica", "timeout": %d}`, testAddress, int64(30*time.Second)),
conn: &conn{
Configuration: Configuration{
Protocol: "grpc",
Target: "@replica",
Protocol: "grpc",
DriverName: "vitess",
Target: "@replica",
},
convert: &converter{
location: time.UTC,
Expand All @@ -94,7 +95,8 @@ func TestOpen(t *testing.T) {
connStr: fmt.Sprintf(`{"address": "%s", "timeout": %d}`, testAddress, int64(30*time.Second)),
conn: &conn{
Configuration: Configuration{
Protocol: "grpc",
Protocol: "grpc",
DriverName: "vitess",
},
convert: &converter{
location: time.UTC,
Expand All @@ -106,8 +108,9 @@ func TestOpen(t *testing.T) {
connStr: fmt.Sprintf(`{"protocol": "grpc", "address": "%s", "target": "ks:0@replica", "timeout": %d}`, testAddress, int64(30*time.Second)),
conn: &conn{
Configuration: Configuration{
Protocol: "grpc",
Target: "ks:0@replica",
Protocol: "grpc",
DriverName: "vitess",
Target: "ks:0@replica",
},
convert: &converter{
location: time.UTC,
Expand All @@ -122,6 +125,7 @@ func TestOpen(t *testing.T) {
conn: &conn{
Configuration: Configuration{
Protocol: "grpc",
DriverName: "vitess",
DefaultLocation: "America/Los_Angeles",
},
convert: &converter{
Expand Down