remove ErrUnsupported and fixes #69
@ -50,6 +50,7 @@ func Connect(cfg *PostgresConfig) (*sqlx.DB, error) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// for postgres user stdlib.GetDefaultDriver() or it fails
|
||||
sql.Register("micro-wrapper-sql", wrapper.NewWrapper(&sqlite.Driver{},
|
||||
wrapper.DatabaseHost("localhost"),
|
||||
wrapper.DatabaseName("mydb"),
|
||||
|
@ -6,9 +6,6 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// ErrUnsupported is an error returned when the underlying driver doesn't provide a given function.
|
||||
var ErrUnsupported = errors.New("operation unsupported by the underlying driver")
|
||||
|
||||
// namedValueToValue converts driver arguments of NamedValue format to Value format. Implemented in the same way as in
|
||||
// database/sql ctxutil.go.
|
||||
func namedValueToValue(named []driver.NamedValue) ([]driver.Value, error) {
|
||||
|
19
conn.go
19
conn.go
@ -13,6 +13,8 @@ var _ driver.Conn = &wrapperConn{}
|
||||
|
||||
// wrapperConn defines a wrapper for driver.Conn
|
||||
type wrapperConn struct {
|
||||
d *wrapperDriver
|
||||
dname string
|
||||
conn driver.Conn
|
||||
opts Options
|
||||
ctx context.Context
|
||||
@ -243,10 +245,7 @@ func (w *wrapperConn) Exec(query string, args []driver.Value) (driver.Result, er
|
||||
// nolint:staticcheck
|
||||
execer, ok := w.conn.(driver.Execer)
|
||||
if !ok {
|
||||
if w.opts.LoggerEnabled {
|
||||
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "Exec", labelUnknown, 0, ErrUnsupported)...).Log(ctx, w.opts.LoggerLevel)
|
||||
}
|
||||
return nil, ErrUnsupported
|
||||
return nil, driver.ErrSkip
|
||||
}
|
||||
|
||||
labels := []string{labelMethod, "Exec", labelQuery, labelUnknown}
|
||||
@ -341,10 +340,11 @@ func (w *wrapperConn) ExecContext(ctx context.Context, query string, args []driv
|
||||
func (w *wrapperConn) Ping(ctx context.Context) error {
|
||||
conn, ok := w.conn.(driver.Pinger)
|
||||
if !ok {
|
||||
if w.opts.LoggerEnabled {
|
||||
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "Ping", labelUnknown, 0, ErrUnsupported)...).Log(ctx, w.opts.LoggerLevel)
|
||||
wc, err := w.d.Open(w.dname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ErrUnsupported
|
||||
return wc.Close()
|
||||
}
|
||||
|
||||
var nctx context.Context
|
||||
@ -389,10 +389,7 @@ func (w *wrapperConn) Query(query string, args []driver.Value) (driver.Rows, err
|
||||
//nolint:staticcheck
|
||||
conn, ok := w.conn.(driver.Queryer)
|
||||
if !ok {
|
||||
if w.opts.LoggerEnabled {
|
||||
w.opts.Logger.Fields(w.opts.LoggerObserver(ctx, "Query", labelUnknown, 0, ErrUnsupported)...).Log(ctx, w.opts.LoggerLevel)
|
||||
}
|
||||
return nil, ErrUnsupported
|
||||
return nil, driver.ErrSkip
|
||||
}
|
||||
|
||||
labels := []string{labelMethod, "Query", labelQuery, labelUnknown}
|
||||
|
@ -32,5 +32,5 @@ func (w *wrapperDriver) Open(name string) (driver.Conn, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &wrapperConn{conn: c, opts: w.opts, ctx: w.ctx}, nil
|
||||
return &wrapperConn{d: w, dname: name, conn: c, opts: w.opts, ctx: w.ctx}, nil
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ func NewOptions(opts ...Option) Options {
|
||||
Tracer: tracer.DefaultTracer,
|
||||
MeterStatsInterval: DefaultMeterStatsInterval,
|
||||
MeterMetricPrefix: DefaultMeterMetricPrefix,
|
||||
LoggerLevel: logger.ErrorLevel,
|
||||
LoggerLevel: logger.DebugLevel,
|
||||
LoggerObserver: DefaultLoggerObserver,
|
||||
}
|
||||
for _, o := range opts {
|
||||
|
Loading…
Reference in New Issue
Block a user