mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
database/sql: allow OpenConnector in a driver.Driver interface
While driver.Connector was previously added to allow non-string connection arguments and access to the context, most users of the sql package will continue to rely on a string DSN. Allow drivers to implement a string DSN to Connector interface that both allows a single parsing of the string DSN and uses the Connector interface which passes available context to the driver dialer. Fixes #22713 Change-Id: Ia0b862262f4c4670effe2538d0d6d43733fea18d Reviewed-on: https://go-review.googlesource.com/77550 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
096b195df5
commit
b44b2feb91
4 changed files with 42 additions and 0 deletions
|
|
@ -3523,6 +3523,19 @@ func TestNamedValueCheckerSkip(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestOpenConnector(t *testing.T) {
|
||||
Register("testctx", &fakeDriverCtx{})
|
||||
db, err := Open("testctx", "people")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
if _, is := db.connector.(*fakeConnector); !is {
|
||||
t.Fatal("not using *fakeConnector")
|
||||
}
|
||||
}
|
||||
|
||||
type ctxOnlyDriver struct {
|
||||
fakeDriver
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue