How it works...
The _ "github.com/go-sql-driver/mysql" line of the code is how you connect various database connectors to the database/sql package. The commands would be similar if you were to connect to Postgres, SQLite, or any others that implement the database/sql interfaces.
Once connected, the package sets up a connection pool that is covered in the Connection pooling, rate limiting, and timeouts for SQL recipe, and you can either directly execute SQL on the connection or create transaction objects that can do everything a connection can do with the commit and rollback commands.
The mysql package provides some convenience support for Go time objects when talking to the database. This recipe also retrieves the username and password from ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access