Getting to Know Our Database

Let’s learn to connect to a database and query it for information.

Working with a database

We most likely need to download an additional package for working with a database server such as PostgreSQL, MySQL, or MongoDB. In this case, we are using PostgreSQL and, therefore, need to download a Go package that allows us to communicate with PostgreSQL. There are two main Go packages for connecting to PostgreSQL—we are going to use the package here, but it is up to you to decide which package best suits the needs of your project.

Note: There is another Go package for working with PostgreSQL called jackc/pgx.

We can download the package of our choice as follows:

Get hands-on with 1200+ tech skills courses.