SkillAgentSearch skills...

Dbstats

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

Install / Use

/learn @cgilling/Dbstats
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

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())
}

View on GitHub
GitHub Stars13
CategoryData
Updated5y ago
Forks7

Languages

Go

Security Score

75/100

Audited on Sep 4, 2020

No findings