Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
sqlhooks
✓ github.com/qustavo/sqlhooks/v2
Registers a custom SQLite driver with hooks that log queries and their execution time.
package main
import (
"context"
"database/sql"
"fmt"
"time"
"github.com/qustavo/sqlhooks/v2"
"github.com/mattn/go-sqlite3"
)
type Hooks struct{}
func (h *Hooks) Before(ctx context.Context, query string, args ...interface{}) (context.Context, error) {
fmt.Printf("> %s %q\n", query, args)
return context.WithValue(ctx, "begin", time.Now()), nil
}
func (h *Hooks) After(ctx context.Context, query string, args ...interface{}) (context.Context, error) {
begin := ctx.Value("begin").(time.Time)
fmt.Printf(". took %s\n", time.Since(begin))
return ctx, nil
}
func main() {
sql.Register("sqlite3-with-hooks", sqlhooks.Wrap(&sqlite3.SQLiteDriver{}, &Hooks{}))
db, _ := sql.Open("sqlite3-with-hooks", ":memory:")
db.Exec("CREATE TABLE foo (id INTEGER)")
}
Upgrade
Version history
2.1.0latest on pkg.go.dev
Audit
Dependencies
No dependency data recorded yet.