db.v3 will compile under go1.7 but requires go1.8+ to provide support for
query cancelation and timeout (via
Go1.8+ comes with new
database/sql features, the ability to pass
context.Context is one of them:
res, err = sess.QueryContext(ctx, "SELECT * FROM authors")
The import path was changed from
import ( ... "upper.io/db.v3" ... )
q := sess.SelectFrom("users") q.Where(...) // This method modified q's internal state.
Used to be valid on
db.v2. This is not longer the case, starting with
queries are immutable, if you’d like to use variables to compose a query you’ll
have to reassign them, like:
q := sess.SelectFrom("users") q = q.Where(...) q.And(...) // Nothing happens, the Where() method does not affect q.
This is also true for
q = sess.Collection("peole").Find() q = q.Where(...) q.Where() // Nothing happens
cond := db.Or(...) cond = cond.Or(...)
In order to help you finding queries that need to be fixed we wrote an special command line tool:
# Install dbcheck go get -u github.com/upper/cmd/dbcheck # Use "..." at the end to check all github.com/my/package's subpackages. dbcheck github.com/my/package/...
If you want to see more details, check out our release notes.