There are two existing projects used to achieve similar goals: https://github.com/ExpansiveWorlds/instrumentedsql https://github.com/gchaincl/sqlhooks
native support could probably improve things a little, but this is a very reasonable approach. On Mon, 10 Sep 2018 at 08:59 Conrad Wood <c...@conradwood.net> wrote: > On Mon, 2018-09-10 at 09:44 +0200, Jan Mercl wrote: > > > > On Mon, Sep 10, 2018 at 8:16 AM Conrad Wood <c...@conradwood.net> > > wrote: > > > > > Wdyt? Is that a patch that would be acceptable and generally > > useful? > > > > It could be tried and evaluated first as an external package. > > > > -- > > -j > > Not sure I understand. The patch would have to be to sql.DB, wouldn't > it? > > I currently open the DB Connection like so: > > db, err = sql.Open("postgres", dbinfo) > > (db is *sql.DB) > > This is current definition of: > > func Open(driverName, dataSourceName string) (*DB, error) > > There's no way atm to pass in an interceptor. > > I am thinking of adding to sql.go: > > 1) type SQLInterceptor func(QueryResult) > > 2) to "type DB struct": interceptor SQLInterceptor > > 3) func (d *DB) SetInterceptor(SQLInterceptor) > > 4) modify the query/exec functions to call the interceptor, if it is > set and if so, call it after the query returns. If no interceptor is > set, it'll continue as currenty. > > How would I test it with an external package? Do you mean copying the > sql package, modifying that and running that instead? > > > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.