Skip to content

A database driver for Go that adds hooks to an existing driver

License

Notifications You must be signed in to change notification settings

majewsky/sqlproxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sqlproxy

GoDoc

This is a driver for the standard library's database/sql package that passes SQL statements through to another driver, but adds hooks to extend the standard library's API.

Example

Augment your existing database driver with statement logging:

import "github.com/majewsky/sqlproxy"

...

sql.Register("postgres-with-logging", &sqlproxy.Driver {
    ProxiedDriverName: "postgresql",
    BeforeQueryHook: func(query string, args[]interface{}) {
        log.Printf("SQL: %s %#v", query, args)
    },
})

As always, sql.Register() may only be called once per driver name, so put this in func init() or a sync.Once.

Caveats

Do not use this code on production databases. This package is intended for development purposes only, and access to it should remain behind a debugging switch. It only implements the bare necessities of the database/sql driver interface and hides optimizations and advanced features of the proxied SQL driver.

About

A database driver for Go that adds hooks to an existing driver

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages