errsql

package module
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 31, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package errsql provides a wrapper for a database/sql/driver.Driver which enables custom error handling before returning any errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddStacktrace added in v0.0.2

func AddStacktrace(err error) error

AddStacktrace adds a github.com/pkg/error.Stacktrace to the error at the point at which the db function is called. It excludes stack frames in the `database/sql` package, and in this package, as well as from the error handler function.

func WrapConnector added in v0.0.6

func WrapConnector(c driver.Connector, eh ErrorHandler) driver.Connector

WrapConnector wraps a database/sql/driver.Connector so that any errors returned by its driver.Connector.Connect method are passed through the error handler. Use this in place of New if you already have a database/sql/driver.Connector instance that you wish to wrap.

Types

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

Driver is the core type implementing the database/sql/driver.Driver interface.

func New

func New(driver driver.Driver, eh ErrorHandler) *Driver

New returns a new Driver instance, which wraps driver and calls eh for any errors. The default error handler just passes the error through, unaltered.

func (*Driver) Open

func (d *Driver) Open(name string) (driver.Conn, error)

func (*Driver) OpenConnector

func (d *Driver) OpenConnector(name string) (driver.Connector, error)

type ErrorHandler

type ErrorHandler func(err error) error

ErrorHandler is a function which is called for any error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL