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
+7.5k Golang : Get YouTube playlist
+6.8k Golang : Find the longest line of text example
+15.2k Golang : How to check if IP address is in range
+7.3k Golang : Of hash table and hash map
+22.1k Golang : Join arrays or slices example
+7.8k Golang : Reverse a string with unicode
+15.6k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content
+6.8k Golang : Join lines with certain suffix symbol example
+46.4k Golang : Encode image to base64 example
+7.8k Golang : Example of how to detect which type of script a word belongs to