How to Work With SQL in Go. Know how to query SQL databases in Go… | by Gleb Sakhnov | Feb, 2022

Know question SQL databases in Go. The best approach

Photograph by Sunder Muthukumaran on Unsplash

sql.DB

Database driver

import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
func principal() 
db, err := sql.Open("mysql",
"person:password@tcp(127.0.0.1:3306)/good day")
if err != nil
log.Deadly(err)

defer db.Shut()
err = db.Ping()
if err != nil
// do one thing right here

Fetching Knowledge from the Database

How Scan() Works

Single-Row Queries

_, err := db.Exec("DELETE FROM customers")  // OK
_, err := db.Question("DELETE FROM customers") // BAD

More Posts