Registry / database / qustavo-sqlhooks-v2

qustavo-sqlhooks-v2

JSON →
library2.1.0gogounverified

Attach hooks to any database/sql driver to intercept and instrument SQL queries.

go get github.com/qustavo/sqlhooks/v2
INSTALL
IMPORT
SIG · QUSTAVO-SQLHOOKS-V
Q
qustavo-sqlhooks-v2
databasegov2.1.0
harness data pending
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)") }
Debug
Known issues
breakingThe v2 module path requires importing with /v2 suffix.
fix
Use import path github.com/qustavo/sqlhooks/v2 instead of github.com/qustavo/sqlhooks.
affects: >=2.0.0
Upgrade
Version history
2.1.0latest on pkg.go.dev
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
2
Resources
qustavo-sqlhooks-v2 — go get qustavo-sqlhooks-v2 · libregistry