]> Cypherpunks repositories - gostls13.git/commit
database/sql: add more examples
authorKevin Burke <kev@inburke.com>
Wed, 31 Jan 2018 03:25:37 +0000 (19:25 -0800)
committerDaniel Theophanes <kardianos@gmail.com>
Sun, 25 Mar 2018 05:09:57 +0000 (05:09 +0000)
commit6f08b9faf2f92752b3246cf52a1f3be76c3882a9
treea429ecd5fefb523f1b4b6cf43d870573fe329b0b
parent782f9ce52f5e021a8d0b0140919afecf0733c4a7
database/sql: add more examples

This aims to expand the coverage of examples showing how the sql
package works, as well as to address a number of issues I've observed
while explaining how the database package works:

- The best way to issue UPDATE or INSERT queries, that don't need
to scan anything in return. (Previously, we had no examples for any
Execute statement).

- How to use prepared statements and transactions.

- How to aggregate arguments from a Query/QueryContext query into
a slice.

Furthermore just having examples in more places should help, as users
click on e.g. the "Rows" return parameter and are treated with the
lack of any example about how Rows is used.

Switch package examples to use QueryContext/QueryRowContext; I think
it is a good practice to prepare users to issue queries with a timeout
attached, even if they are not using it immediately.

Change-Id: I4e63af91c7e4fff88b25f820906104ecefde4cc3
Reviewed-on: https://go-review.googlesource.com/91015
Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
Run-TryBot: Daniel Theophanes <kardianos@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/database/sql/example_test.go
src/database/sql/sql.go