• Kevin Burke's avatar
    database/sql: add more examples · 6f08b9fa
    Kevin Burke authored
    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/91015Reviewed-by: 's avatarDaniel Theophanes <kardianos@gmail.com>
    Run-TryBot: Daniel Theophanes <kardianos@gmail.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    6f08b9fa
sql.go 83.8 KB