How it works...
As mentioned in the previous recipe, Connecting the database, the Open function may just verify the connection details, but it is not mandatory to connect the database immediately. The actual connection to the database is usually lazy loaded and it is created by the first execution of statement against the database.
The pointer to the DB structure provides the Ping method, which usually does an idempotent call to the database. The variation to the Ping method is PingContext, which just adds the ability to cancel or time out the database call. Note that if the Ping function fails, the connection is removed from the database pool.
The pointer to the DB struct also provides the method Conn to retrieve the connection from the ...
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