How it works...

The _ "github.com/go-sql-driver/mysql" line of code is how you connect various database connectors to the database/sql package. There are also alternative MySQL packages that can be imported in the same way for similar results. The commands would be similar if you were to connect to PostgreSQL, 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 execute SQL on the connection directly, 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 the MYSQLUSERNAME and MYSQLPASSWORD environment variables.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.137.218