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
+30.5k Get client IP Address in Go
+14.5k Golang : Rename directory
+32.2k Golang : Convert []string to []byte examples
+14k Golang : concatenate(combine) strings
+28.8k Golang : Detect (OS) Operating System
+14.6k Golang : Send email with attachment(RFC2822) using Gmail API example
+6.5k Elasticsearch : Shutdown a local node
+8.2k Golang : Get final or effective URL with Request.URL example
+15k Golang : package is not in GOROOT during compilation
+19k Golang : Padding data for encryption and un-padding data for decryption
+23.9k Golang : Use regular expression to validate domain name
+39.2k Golang : How to read CSV file