2019-04-13 07:44:06 +00:00
|
|
|
// +build go1.10
|
|
|
|
|
2018-07-06 16:09:34 +00:00
|
|
|
package pq
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"database/sql/driver"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Connector represents a fixed configuration for the pq driver with a given
|
|
|
|
// name. Connector satisfies the database/sql/driver Connector interface and
|
|
|
|
// can be used to create any number of DB Conn's via the database/sql OpenDB
|
|
|
|
// function.
|
|
|
|
//
|
|
|
|
// See https://golang.org/pkg/database/sql/driver/#Connector.
|
|
|
|
// See https://golang.org/pkg/database/sql/#OpenDB.
|
2019-04-13 07:44:06 +00:00
|
|
|
type connector struct {
|
|
|
|
name string
|
2018-07-06 16:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Connect returns a connection to the database using the fixed configuration
|
|
|
|
// of this Connector. Context is not used.
|
2019-04-13 07:44:06 +00:00
|
|
|
func (c *connector) Connect(_ context.Context) (driver.Conn, error) {
|
|
|
|
return (&Driver{}).Open(c.name)
|
2018-07-06 16:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Driver returnst the underlying driver of this Connector.
|
2019-04-13 07:44:06 +00:00
|
|
|
func (c *connector) Driver() driver.Driver {
|
2018-07-06 16:09:34 +00:00
|
|
|
return &Driver{}
|
|
|
|
}
|
|
|
|
|
2019-04-13 07:44:06 +00:00
|
|
|
var _ driver.Connector = &connector{}
|
|
|
|
|
2018-07-06 16:09:34 +00:00
|
|
|
// NewConnector returns a connector for the pq driver in a fixed configuration
|
2019-04-13 07:44:06 +00:00
|
|
|
// with the given name. The returned connector can be used to create any number
|
2018-07-06 16:09:34 +00:00
|
|
|
// of equivalent Conn's. The returned connector is intended to be used with
|
|
|
|
// database/sql.OpenDB.
|
|
|
|
//
|
|
|
|
// See https://golang.org/pkg/database/sql/driver/#Connector.
|
|
|
|
// See https://golang.org/pkg/database/sql/#OpenDB.
|
2019-04-13 07:44:06 +00:00
|
|
|
func NewConnector(name string) (driver.Connector, error) {
|
|
|
|
return &connector{name: name}, nil
|
2018-07-06 16:09:34 +00:00
|
|
|
}
|