Deleting your first record from MySQL
Consider a scenario where an employee has left the organization and you want to revoke their details from the database. In that case, we can use the SQL DELETE statement, which we will be covering in this recipe.
How to do it…
- Install the github.com/go-sql-driver/mysqlandgithub.com/gorilla/muxpackages, using thego getcommand, as follows:
$ go get github.com/go-sql-driver/mysql $ go get github.com/gorilla/mux
- Create delete-record-mysql.go. Then we connect to the MySQL database, delete the name of an employee from the database, and write the number of records deleted from a database to an HTTP response stream, as follows:
package main
import 
(
  "database/sql"
  "fmt"
  "log"
  "net/http"
  "github.com/go-sql-driver/mysql"
  "github.com/gorilla/mux"
)
const 
(
  CONN_HOST = "localhost"
  CONN_PORT = "8080"
  DRIVER_NAME = "mysql"
  DATA_SOURCE_NAME = "root:password@/mydb"
)
var db *sql.DB
var connectionError error
func init() 
{
  db, connectionError... 
                                             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
     
         
                 
                 
                 
                 
                 
                 
                 
                 
                 
        