In this section, we're going to see how to delete data from a database. We'll still use the old code that we developed in the previous section and make some minor changes to it. Check out the following code:
package main import ( _ "github.com/mattn/go-sqlite3" "database/sql" "fmt" ) type Profile struct{ ProfileId int FirstName string LastName string Age int } func main(){ db, err := sql.Open("sqlite3", "./personal.db") checkError(err) var profile Profile rows, err := db.Query("select ProfileId, FirstName, LastName, Age from Profile") checkError(err) for rows.Next(){ err := rows.Scan(&profile.ProfileId, &profile.FirstName, &profile.LastName, &profile.Age) checkError(err) fmt.Println(profile) } rows.Close() db.Close() } func checkError(err error) { if (err != nil) { panic(err) } }
The output of the preceding code will be as follows:
Now, to delete data, say row 3
in this case, you will have to make...