The sql package
The database/sql package defines the SQL database interface. But it doesn’t implement that interface. The drivers, such as go-sqlite3 or pq (the PostgreSQL driver), do it.
The database access always starts with connecting to the database itself using sql.Open. From there, we can decide what to do. Usually, we execute SQL queries. Some queries require data to be returned, such as SELECT queries, and others don’t, such as INSERT or UPDATE queries. For the former, we can use Query or QueryRow methods that return Rows and Row objects, respectively. We can use Exec, which will return a Result object for cases where we don’t need to get the results.
Let’s look at the querying part in more detail.
Querying
As mentioned, the first thing that we need to do is open the database. As was shown in the previous example, we can do it like this:
db, err := sql.Open("sqlite3", "./database.db")
Once we have the...