https://github.com/majewsky/sqlproxy
A database driver for Go that adds hooks to an existing driver
https://github.com/majewsky/sqlproxy
Last synced: 28 days ago
JSON representation
A database driver for Go that adds hooks to an existing driver
- Host: GitHub
- URL: https://github.com/majewsky/sqlproxy
- Owner: majewsky
- License: apache-2.0
- Created: 2017-03-03T18:40:05.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-05-24T08:04:57.000Z (over 6 years ago)
- Last Synced: 2025-01-16T20:22:40.596Z (12 months ago)
- Language: Go
- Size: 13.7 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sqlproxy
[](https://godoc.org/github.com/majewsky/sqlproxy)
This is a driver for the standard library's [`database/sql` package][go-sql]
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:
```go
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.
[go-sql]: https://golang.org/pkg/database/sql/