Vasiliy Tolstov
dbce4a1d9e
Some checks failed
dependabot-automerge / automerge (pull_request) Has been skipped
autoapprove / autoapprove (pull_request) Failing after 4s
automerge / automerge (pull_request) Failing after 4s
codeql / analyze (go) (pull_request) Failing after 6s
prbuild / test (pull_request) Failing after 5s
prbuild / lint (pull_request) Failing after 6s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
130 lines
3.4 KiB
Go
130 lines
3.4 KiB
Go
package wrapper
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
)
|
|
|
|
func wrapDriver(d driver.Driver, opts Options) driver.Driver {
|
|
if _, ok := d.(driver.DriverContext); ok {
|
|
return &wrapperDriver{driver: d, opts: opts}
|
|
}
|
|
return struct{ driver.Driver }{&wrapperDriver{driver: d, opts: opts}}
|
|
}
|
|
|
|
/*
|
|
func wrapStmt(stmt driver.Stmt, query string, opts Options) driver.Stmt {
|
|
var (
|
|
_, hasExeCtx = stmt.(driver.StmtExecContext)
|
|
_, hasQryCtx = stmt.(driver.StmtQueryContext)
|
|
wc, hasColConv = stmt.(driver.ColumnConverter) //nolint:staticcheck
|
|
wn, hasNamValChk = stmt.(driver.NamedValueChecker)
|
|
)
|
|
|
|
ws := &wrapperStmt{stmt: stmt, query: query, opts: opts}
|
|
switch {
|
|
case !hasExeCtx && !hasQryCtx && !hasColConv && !hasNamValChk:
|
|
return struct {
|
|
driver.Stmt
|
|
}{ws}
|
|
case !hasExeCtx && hasQryCtx && !hasColConv && !hasNamValChk:
|
|
return struct {
|
|
driver.Stmt
|
|
driver.StmtQueryContext
|
|
}{ws, ws}
|
|
case hasExeCtx && !hasQryCtx && !hasColConv && !hasNamValChk:
|
|
return struct {
|
|
driver.Stmt
|
|
driver.StmtExecContext
|
|
}{ws, ws}
|
|
case hasExeCtx && hasQryCtx && !hasColConv && !hasNamValChk:
|
|
return struct {
|
|
driver.Stmt
|
|
driver.StmtExecContext
|
|
driver.StmtQueryContext
|
|
}{ws, ws, ws}
|
|
case !hasExeCtx && !hasQryCtx && hasColConv && !hasNamValChk:
|
|
return struct {
|
|
driver.Stmt
|
|
driver.ColumnConverter
|
|
}{ws, wc}
|
|
case !hasExeCtx && hasQryCtx && hasColConv && !hasNamValChk:
|
|
return struct {
|
|
driver.Stmt
|
|
driver.StmtQueryContext
|
|
driver.ColumnConverter
|
|
}{ws, ws, wc}
|
|
case hasExeCtx && !hasQryCtx && hasColConv && !hasNamValChk:
|
|
return struct {
|
|
driver.Stmt
|
|
driver.StmtExecContext
|
|
driver.ColumnConverter
|
|
}{ws, ws, wc}
|
|
case hasExeCtx && hasQryCtx && hasColConv && !hasNamValChk:
|
|
return struct {
|
|
driver.Stmt
|
|
driver.StmtExecContext
|
|
driver.StmtQueryContext
|
|
driver.ColumnConverter
|
|
}{ws, ws, ws, wc}
|
|
case !hasExeCtx && !hasQryCtx && !hasColConv && hasNamValChk:
|
|
return struct {
|
|
driver.Stmt
|
|
driver.NamedValueChecker
|
|
}{ws, wn}
|
|
case !hasExeCtx && hasQryCtx && !hasColConv && hasNamValChk:
|
|
return struct {
|
|
driver.Stmt
|
|
driver.StmtQueryContext
|
|
driver.NamedValueChecker
|
|
}{ws, ws, wn}
|
|
case hasExeCtx && !hasQryCtx && !hasColConv && hasNamValChk:
|
|
return struct {
|
|
driver.Stmt
|
|
driver.StmtExecContext
|
|
driver.NamedValueChecker
|
|
}{ws, ws, wn}
|
|
case hasExeCtx && hasQryCtx && !hasColConv && hasNamValChk:
|
|
return struct {
|
|
driver.Stmt
|
|
driver.StmtExecContext
|
|
driver.StmtQueryContext
|
|
driver.NamedValueChecker
|
|
}{ws, ws, ws, wn}
|
|
case !hasExeCtx && !hasQryCtx && hasColConv && hasNamValChk:
|
|
return struct {
|
|
driver.Stmt
|
|
driver.ColumnConverter
|
|
driver.NamedValueChecker
|
|
}{ws, wc, wn}
|
|
case !hasExeCtx && hasQryCtx && hasColConv && hasNamValChk:
|
|
return struct {
|
|
driver.Stmt
|
|
driver.StmtQueryContext
|
|
driver.ColumnConverter
|
|
driver.NamedValueChecker
|
|
}{ws, ws, wc, wn}
|
|
case hasExeCtx && !hasQryCtx && hasColConv && hasNamValChk:
|
|
return struct {
|
|
driver.Stmt
|
|
driver.StmtExecContext
|
|
driver.ColumnConverter
|
|
driver.NamedValueChecker
|
|
}{ws, ws, wc, wn}
|
|
case hasExeCtx && hasQryCtx && hasColConv && hasNamValChk:
|
|
return struct {
|
|
driver.Stmt
|
|
driver.StmtExecContext
|
|
driver.StmtQueryContext
|
|
driver.ColumnConverter
|
|
driver.NamedValueChecker
|
|
}{ws, ws, ws, wc, wn}
|
|
}
|
|
panic("unreachable")
|
|
}
|
|
*/
|
|
|
|
// WrapConn allows an existing driver.Conn to be wrapped.
|
|
func WrapConn(c driver.Conn, opts ...Option) driver.Conn {
|
|
return wrapConn(c, NewOptions(opts...))
|
|
}
|