Connecting to a database
There are two ways you can incorporate a database into your applications: you can use a database server or an embedded database. Let’s start by defining what those are.
A database server runs as a separate process on the same or a different host but is independent of your application. Usually, your application connects to this database server through a network connection, so you have to know its network address and port. There is usually a library you have to import into your program, a “database driver” specific to the database server you use. This driver provides the interface between your application and the database by managing the connections, queries, transactions, and so on.
An embedded database is not a separate process. It is included in your application as a library and runs in the same address space. A database driver acts as an adapter that presents a standard interface (i.e., using the database/sql
package) to the application...