row=db.QueryRow("SELECT * FROM todos WHERE id = ?",100_000)
err=row.Scan(&id,&subject,&todo)
// We can also use this short hand!
err=db.QueryRow("SELECT * FROM todos WHERE id = ?",100_000).Scan(&id,&subject,&todo)
iferr!=nil{
log.Print(err.Error())
}
// There is no row.Close(). Rows objects have a Close() method. No explicit closing required.
//Prepared Queries
// If you will be using the same query over and over you should just prepare the query.
// $N is the postgres query param which SQLite can use too ? is mysql's
//Under the hood, db.Query() actually prepares, executes, and closes a prepared statement
// That’s three round-trips to the database.
stmt,err:=db.Prepare("SELECT * FROM todos WHERE id = $N")
iferr!=nil{
log.Fatal(err)
}
//This prepared statement *sql.Stmt is tied to the database connection from which it was created, and it holds onto that connection until you call stmt.Close()