Skip to content

Commit 72a271a

Browse files
committed
implement driver.Validator interface
1 parent 096e398 commit 72a271a

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Diff for: conn.go

+18
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,21 @@ func (conn *Conn) ResetSession(ctx context.Context) error {
353353
}
354354
return err
355355
}
356+
357+
// the same as driver.Validator.
358+
// Copied from database/sql/driver/driver.go for supporting Go 1.15
359+
type validator interface {
360+
// IsValid is called prior to placing the connection into the
361+
// connection pool. The connection will be discarded if false is returned.
362+
IsValid() bool
363+
}
364+
365+
// IsValid implements driver.Validator.
366+
// It calls the IsValid method of the original connection.
367+
// If the original connection does not satisfy "database/sql/driver".Validator, it always returns true.
368+
func (conn *Conn) IsValid() bool {
369+
if v, ok := conn.Conn.(validator); ok {
370+
return v.IsValid()
371+
}
372+
return true
373+
}

Diff for: conn_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ var _ driver.Queryer = (*Conn)(nil)
1212
var _ driver.QueryerContext = (*Conn)(nil)
1313
var _ namedValueChecker = (*Conn)(nil)
1414
var _ sessionResetter = (*Conn)(nil)
15+
var _ validator = (*Conn)(nil)

0 commit comments

Comments
 (0)