dbtimer

package module
v0.0.0-...-7002f37 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2017 License: MIT Imports: 5 Imported by: 4

README

dbtimer

A small library for timing database interactions

To use:

	dbtimer.SetTimerLoggerFunc(func(ti dbtimer.TimerInfo) {
		fmt.Printf("%s %s %v %v %d\n",ti.Method, ti.Query, ti.Args, ti.Err, ti.End.Sub(ti.Start).Nanoseconds()/1000)
	})
	db, err := sql.Open("timer", "postgres postgres://jon:jon@localhost/jon?sslmode=disable")

Then use the db as expected.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetTimerLogger

func SetTimerLogger(tl TimerLogger)

func SetTimerLoggerFunc

func SetTimerLoggerFunc(lf TimerLoggerFunc)

Types

type Conn

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

func (*Conn) Begin

func (c *Conn) Begin() (driver.Tx, error)

Begin starts and returns a new transaction.

func (*Conn) Close

func (c *Conn) Close() error

Close invalidates and potentially stops any current prepared statements and transactions, marking this connection as no longer in use.

Because the sql package maintains a free pool of connections and only calls Close when there's a surplus of idle connections, it shouldn't be necessary for drivers to do their own connection caching.

func (*Conn) Exec

func (c *Conn) Exec(query string, args []driver.Value) (driver.Result, error)

func (*Conn) Prepare

func (c *Conn) Prepare(query string) (driver.Stmt, error)

Prepare returns a prepared statement, bound to this connection.

type Driver

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

func (*Driver) Open

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

Open returns a new connection to the database. The name is a string in a driver-specific format.

Open may return a cached connection (one previously closed), but doing so is unnecessary; the sql package maintains a pool of idle connections for efficient re-use.

The returned connection is only used by one goroutine at a time.

type NoExecConn

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

func (*NoExecConn) Begin

func (c *NoExecConn) Begin() (driver.Tx, error)

Begin starts and returns a new transaction.

func (*NoExecConn) Close

func (c *NoExecConn) Close() error

Close invalidates and potentially stops any current prepared statements and transactions, marking this connection as no longer in use.

Because the sql package maintains a free pool of connections and only calls Close when there's a surplus of idle connections, it shouldn't be necessary for drivers to do their own connection caching.

func (*NoExecConn) Prepare

func (c *NoExecConn) Prepare(query string) (driver.Stmt, error)

Prepare returns a prepared statement, bound to this connection.

type Stmt

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

func (*Stmt) Close

func (s *Stmt) Close() error

Close closes the statement.

As of Go 1.1, a Stmt will not be closed if it's in use by any queries.

func (*Stmt) Exec

func (s *Stmt) Exec(args []driver.Value) (driver.Result, error)

Exec executes a query that doesn't return rows, such as an INSERT or UPDATE.

func (*Stmt) NumInput

func (s *Stmt) NumInput() int

NumInput returns the number of placeholder parameters.

If NumInput returns >= 0, the sql package will sanity check argument counts from callers and return errors to the caller before the statement's Exec or Query methods are called.

NumInput may also return -1, if the driver doesn't know its number of placeholders. In that case, the sql package will not sanity check Exec or Query argument counts.

func (*Stmt) Query

func (s *Stmt) Query(args []driver.Value) (driver.Rows, error)

Query executes a query that may return rows, such as a SELECT.

type TimerInfo

type TimerInfo struct {
	Method string
	Query  string
	Start  time.Time
	End    time.Time
	Args   []driver.Value
	Err    error
}

type TimerLogger

type TimerLogger interface {
	Log(TimerInfo)
}

type TimerLoggerFunc

type TimerLoggerFunc func(TimerInfo)

func (TimerLoggerFunc) Log

func (tlf TimerLoggerFunc) Log(ti TimerInfo)

type Tx

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

func (*Tx) Commit

func (t *Tx) Commit() error

func (*Tx) Rollback

func (t *Tx) Rollback() error

Jump to

Keyboard shortcuts

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