diff options
| author | James Lawrence <jljatone@gmail.com> | 2017-08-05 06:04:19 -0400 |
|---|---|---|
| committer | Daniel Theophanes <kardianos@gmail.com> | 2017-09-23 20:47:06 +0000 |
| commit | e6358c798b3001e98b6f7f4c3e2d906cf48533b2 (patch) | |
| tree | 2cccc26a32cc67e720372a67423c7418f4382c5d /src/database/sql/driver | |
| parent | 6936671ed1c3a1dd25e0eea635ee2bdc86acd463 (diff) | |
| download | go-e6358c798b3001e98b6f7f4c3e2d906cf48533b2.tar.xz | |
database/sql: add OpenDB to directly create a *DB without a DSN.
The current Open method limits the ability for driver maintainers
to expose options for their drivers by forcing all the configuration
to pass through the DSN in order to create a *DB.
This CL allows driver maintainers to write their own initialization
functions that return a *DB making configuration of the underlying
drivers easier.
Fixes #20268
Change-Id: Ib10b794f36a201bbb92c23999c8351815d38eedb
Reviewed-on: https://go-review.googlesource.com/53430
Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
Run-TryBot: Daniel Theophanes <kardianos@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/database/sql/driver')
| -rw-r--r-- | src/database/sql/driver/driver.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/database/sql/driver/driver.go b/src/database/sql/driver/driver.go index 0262ca24ba..f5a2e7c16c 100644 --- a/src/database/sql/driver/driver.go +++ b/src/database/sql/driver/driver.go @@ -55,6 +55,29 @@ type Driver interface { Open(name string) (Conn, error) } +// Connector is an optional interface that drivers can implement. +// It allows drivers to provide more flexible methods to open +// database connections without requiring the use of a DSN string. +type Connector interface { + // Connect returns a connection to the database. + // Connect may return a cached connection (one previously + // closed), but doing so is unnecessary; the sql package + // maintains a pool of idle connections for efficient re-use. + // + // The provided context.Context is for dialing purposes only + // (see net.DialContext) and should not be stored or used for + // other purposes. + // + // The returned connection is only used by one goroutine at a + // time. + Connect(context.Context) (Conn, error) + + // Driver returns the underlying Driver of the Connector, + // mainly to maintain compatibility with the Driver method + // on sql.DB. + Driver() Driver +} + // ErrSkip may be returned by some optional interfaces' methods to // indicate at runtime that the fast path is unavailable and the sql // package should continue as if the optional interface was not |
