Golang database/sql.Tx.Exec and Rollback functions examples
package database/sql
Exec executes a query that doesn't return rows. For example: an INSERT and UPDATE.
Rollback aborts the transaction.
Golang database/sql.Tx.Exec and Rollback functions usage examples
Example 1:
result, err := tx.Exec(`INSERT INTO order_request (member_id) VALUES (?)`, memberId)
if err != nil {
log.Print(err.Error())
}
orderId, err := result.LastInsertId()
Example 2:
_, err = tx.Exec("DELETE FROM "+SqlTableName+" WHERE id = $1", id)
if err != nil {
tx.Rollback()
return err
}
References :
Advertisement
Something interesting
Tutorials
+17.5k Golang : Clone with pointer and modify value
+14.3k Golang : How to shuffle elements in array or slice?
+8.1k Golang : Append and add item in slice
+10.1k Golang : Test a slice of integers for odd and even numbers
+19.8k Golang : Append content to a file
+19.9k Golang : How to get time from unix nano example
+11.8k Golang : Verify Linux user password again before executing a program example
+21.1k Golang : Sort and reverse sort a slice of strings
+9.6k Javascript : Read/parse JSON data from HTTP response
+11.6k Android Studio : Create custom icons for your application example
+7.3k Golang : How to convert strange string to JSON with json.MarshalIndent
+28.8k Golang : Detect (OS) Operating System