diff --git a/fix.go b/fix.go new file mode 100644 index 0000000..5836f14 --- /dev/null +++ b/fix.go @@ -0,0 +1,17 @@ +package fix + +import ( + "context" + "database/sql" +) + +// FixConnectionLeak ensures connections are properly returned to the pool +// when context is cancelled, preventing connection leaks. +func QueryWithContext(ctx context.Context, db *sql.DB, query string, args ...interface{}) (*sql.Rows, error) { + conn, err := db.Conn(ctx) + if err != nil { + return nil, err + } + defer conn.Close() + return conn.QueryContext(ctx, query, args...) +}