Golang database/sql/driver.Execer type example

package database/sql/driver

Execer is an optional interface that may be implemented by a Conn.

If a Conn does not implement Execer, the sql package's DB.Exec will first prepare a query, execute the statement, and then close the statement.

Exec may return ErrSkip.

Golang database/sql/driver.Execer type usage example

 // creates a new wrap and registers it with the name "debug"
 wrap := dbwrap.New("debug", pqdrv(0))
 ...

 // is used instead of conn.Exec
 wrap.HandleExec = func(exec driver.Execer, query string, args []driver.Value) (driver.Result, error) {
 fmt.Println("exec: ", query)
 // do the real Exec and return the result
 return exec.Exec(query, args)
 }

References :

https://github.com/metakeule/dbwrap/blob/master/example/simple.go

http://golang.org/pkg/database/sql/driver/#Execer

Advertisement