Skip to content

Commit

Permalink
Rename to sqlhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Chain committed Apr 20, 2016
1 parent e8f3dc0 commit 60b4a3c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -12,15 +12,15 @@ package main

func main() {
// Define your hooks
hooks := sqlhook.Hooks{
Query: func(fn sqlhook.QueryFn, query string, args ...interface{}) (driver.Rows, error) {
hooks := sqlhooks.Hooks{
Query: func(fn sqlhooks.QueryFn, query string, args ...interface{}) (driver.Rows, error) {
defer func(t time.Time) {
log.Printf("query: %s, args: %v, took: %s\n", query, args, time.Since(t))
}(time.Now())

return fn()
},
Exec: func(fn sqlhook.ExecFn, query string, args ...interface{}) (driver.Result, error) {
Exec: func(fn sqlhooks.ExecFn, query string, args ...interface{}) (driver.Result, error) {
defer func(t time.Time) {
log.Printf("exec: %s, args: %v, took: %s\n", query, args, time.Since(t))
}(time.Now())
Expand All @@ -31,7 +31,7 @@ func main() {

// Register the driver
// sqlite-hooked is the attached driver, and sqlite3 is where we're attaching to
sqlhook.Register("sqlite-hooked", sqlhook.NewDriver("sqlite3", &hooks))
sqlhooks.Register("sqlite-hooked", sqlhooks.NewDriver("sqlite3", &hooks))

// Connect to attached driver
db, _ := sql.Open("sqlite-hooked", ":memory:")
Expand All @@ -43,7 +43,7 @@ func main() {
}
```

sqlhook will intercept Query and Exec functions and instead run your hooks, output will look like:
sqlhooks will intercept Query and Exec functions and instead run your hooks, output will look like:
```
2000/01/01 00:01:02 exec: CREATE TABLE t (id INTEGER, text VARCHAR(16)), args: [], took: 226.169µs
2000/01/01 00:01:02 exec: INSERT into t (text) VALUES(?), (?)), args: [foo bar], took: 26.822µs
Expand Down
2 changes: 1 addition & 1 deletion fakedb_test.go
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package sqlhook
package sqlhooks

import (
"database/sql"
Expand Down
2 changes: 1 addition & 1 deletion sqlhook.go → sqlhooks.go
@@ -1,4 +1,4 @@
package sqlhook
package sqlhooks

import (
"database/sql"
Expand Down
2 changes: 1 addition & 1 deletion sqlhook_test.go → sqlhooks_test.go
@@ -1,4 +1,4 @@
package sqlhook
package sqlhooks

import (
"database/sql"
Expand Down

0 comments on commit 60b4a3c

Please sign in to comment.