DATA-DOG / go-sqlmock

Sql mock driver for golang to test database interactions
Other
6.16k stars 407 forks source link

Access to underlying driver.Driver? #276

Closed slnt closed 2 years ago

slnt commented 3 years ago

I am using the package sqlmw to write an interceptor that adds logging and tracing to an arbitrary underlying driver. I'd like to test this with sqlmock but am running into a roadblock due to the fact that the sqlmw.Driver functions requires a driver.Driver. The driver that is implemented in sqlmock, however, is unexported, making the use of the library rather tricky... I'm not sure about what the RightWay™ might be to expose the underlying driver implementation that Sqlmock uses, especially such that it is openable by sql.Open.

dolmen commented 2 years ago

You can get access to the driver via db.Driver().

Example on the Go Playground:

    db, _, err := sqlmock.New()
    drv := db.Driver()
Ghvstcode commented 2 years ago

Hi, It seems @dolmen answered your question & this thread has been inactive for a while so I will be closing this.