Golang database/sql.Tx.QueryRow function examples
package database/sql
QueryRow executes a query that is expected to return at most one row. QueryRow always return a non-nil value. Errors are deferred until Row's Scan method is called.
Golang database/sql.Tx.QueryRow function usage examples
Example 1:
var num int
err = txn.QueryRow("SELECT COUNT(*) FROM temp").Scan(&num)
if err != nil {
fmt.Println(err)
}
if num != 500 {
fmt.Printf("expected 500 items, not %d", num)
}
Example 2:
var name string
err = tx.QueryRow(`
UPDATE jobs
SET build_number_seq = build_number_seq + 1
WHERE name = $1
RETURNING build_number_seq
`, job).Scan(&name)
if err != nil {
return builds.Build{}, err
}
Reference :
Advertisement
Something interesting
Tutorials
+13.4k Golang : error parsing regexp: invalid or unsupported Perl syntax
+6.1k Java : Human readable password generator
+8.2k Golang : Routes multiplexer routing example with regular expression control
+9.4k Golang : Find the length of big.Int variable example
+6.4k CodeIgniter : form input set_value cause " to become & quot
+5.2k Golang : The Tao of importing package
+7.5k Golang : Process json data with Jason package
+19.7k Golang : Archive directory with tar and gzip
+8.8k Golang : Gorilla web tool kit schema example
+16.9k Golang : How to generate QR codes?
+14.8k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name
+11.7k Golang : Calculations using complex numbers example