Skip to content

A golang database/sql driver wrapper that provides hooks around database operations in order to gather usage/performance statistics.

License

Notifications You must be signed in to change notification settings

cgilling/dbstats

Repository files navigation

dbstats

Build Status Coverage GoDoc

A golang database/sql driver wrapper that provides hooks around database operations in order to gather usage/performance statistics.

Usage

dbstats provides a wrapper for a database/sql/driver.Driver . This is done by wrapping the Driver's Open function and then registering the new wrapped driver with database/sql. Once the driver has been wrapped, Hooks can be registered in order to gather various statistics. A very basic Hook CounterHook is provided by this package.

import (
  "database/sql"
  
  "github.com/cgilling/dbstats"
  "github.com/lib/pq"
)

var pqStats dbstats.CounterHook

func init() {
  s := dbstats.New(pq.Open)
  s.AddHook(pqStats)
  sql.Register("pqstats", s)
}

func main() {
  db, err := sql.Open("pqstats", "dbname=pqgotest"); // use the normal database connection string
  ... // use db as normal
  fmt.Printf("%d queries and %d execs\n", pqStats.Queries(), pqStats.Execs())
}

About

A golang database/sql driver wrapper that provides hooks around database operations in order to gather usage/performance statistics.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages