Do not release queries in Get/Select. Fix #25

Releasing query objects in Get/Select could easily lead to
double-releases, which can cause dangerous and tricky data races.

Remove the query field of Iterx and its usages (all release-related).
This is a breaking API change, because it removes the exported method
ReleaseQuery.

Update documenting examples to demonstrate the deferred query release
pattern clients can use to manage query release.
This commit is contained in:
Josh Giles
2017-11-11 09:27:15 -05:00
committed by Michał Matczuk
parent 255429a93c
commit cbe2659e0d
2 changed files with 4 additions and 27 deletions

View File

@@ -146,6 +146,7 @@ func TestExample(t *testing.T) {
q := gocqlx.Query(session.Query(stmt), names).BindMap(qb.M{
"first_name": "Patricia",
})
defer q.Release()
var p Person
if err := gocqlx.Get(&p, q.Query); err != nil {
@@ -165,6 +166,7 @@ func TestExample(t *testing.T) {
q := gocqlx.Query(session.Query(stmt), names).BindMap(qb.M{
"first_name": []string{"Patricia", "Igy", "Ian"},
})
defer q.Release()
var people []Person
if err := gocqlx.Select(&people, q.Query); err != nil {
@@ -190,6 +192,7 @@ func TestExample(t *testing.T) {
ToCql()
q := gocqlx.Query(session.Query(stmt), names).BindStruct(p)
defer q.Release()
var people []Person
if err := gocqlx.Select(&people, q.Query); err != nil {