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
+11.9k Golang : Determine if time variables have same calendar day
+9.3k Golang : Temperatures conversion example
+7.4k Golang : Accessing dataframe-go element by row, column and name example
+5.9k AWS S3 : Prevent Hotlinking policy
+11.2k Golang : How to pipe input data to executing child process?
+7.1k Javascript : How to get JSON data from another website with JQuery or Ajax ?
+6.7k Golang : Derive cryptographic key from passwords with Argon2
+8.3k Golang : Configure Apache and NGINX to access your Go service example
+19.3k Golang : Get host name or domain name from IP address
+7.1k Golang : Get Alexa ranking data example
+18.2k Golang : Get command line arguments
+8.8k Yum Error: no such table: packages