Skip to content

Commit

Permalink
Merge pull request #13 from knocknote/feature/add-nil-check-for-rw-qu…
Browse files Browse the repository at this point in the history
…eries

Add nil check for getting read/write queries
  • Loading branch information
goccy authored Apr 28, 2019
2 parents 9a03cb4 + 239f575 commit f2c6b32
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions database/sql/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,12 @@ func TestTransaction(t *testing.T) {
defer db.Close()
tx, err := db.Begin()
checkErr(t, err)
if readQueries := tx.ReadQueries(); len(readQueries) > 0 {
t.Fatal("invalid read queries")
}
if writeQueries := tx.WriteQueries(); len(writeQueries) > 0 {
t.Fatal("invalid write queries")
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
t.Run("prepare context", func(t *testing.T) {
Expand Down
6 changes: 6 additions & 0 deletions database/sql/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,17 @@ func (proxy *Tx) AfterCommitCallback(success func() error, failure func(bool, []

// WriteQueries informations of executed INSERT/UPDATE/DELETE query
func (proxy *Tx) WriteQueries() []*connection.QueryLog {
if proxy.tx == nil {
return []*connection.QueryLog{}
}
return proxy.tx.WriteQueries
}

// ReadQueries informations of executed SELECT query
func (proxy *Tx) ReadQueries() []*connection.QueryLog {
if proxy.tx == nil {
return []*connection.QueryLog{}
}
return proxy.tx.ReadQueries
}

Expand Down

0 comments on commit f2c6b32

Please sign in to comment.