lib / pq

Pure Go Postgres driver for database/sql
https://pkg.go.dev/github.com/lib/pq
MIT License
8.98k stars 909 forks source link

Correctly implement database/sql/driver.Driver for better wrappability #1005

Closed igorwwwwwwwwwwwwwwwwwwww closed 3 years ago

igorwwwwwwwwwwwwwwwwwwww commented 3 years ago

I was trying to wrap pq with instrumentedsql, but it does not implement the database/sql/driver.Driver type.

Minimal example:

package main

import (
    "database/sql"

    "github.com/lib/pq"
    "github.com/luna-duclos/instrumentedsql"
    instrumentedsqltrace "github.com/luna-duclos/instrumentedsql/opentracing"
)

func main() {
    sql.Register("instrumented-postgres", instrumentedsql.WrapDriver(pq.Driver{}, instrumentedsql.WithTracer(instrumentedsqltrace.NewTracer(false))))
}

Compile error:

./minimal.go:12:76: cannot use pq.Driver literal (type pq.Driver) as type driver.Driver in argument to instrumentedsql.WrapDriver:
    pq.Driver does not implement driver.Driver (Open method has pointer receiver)

This patch aims to address this by changing the pointer receiver to a value receiver.