PostgreSQL is an open source relational database system that has been around for well over a decade and has proven to be a great all around storage choice when developing a web application.
In this series we are going to walk through everything from first installing PostgreSQL 9.5 all the way to using it with a Go application. While this post will cover all of the basics required to get started using SQL with Golang, it is not a full course on SQL. It is instead intended to guide you by giving you enough information to be productive, while not overloading you with details that can be learned as you progress.
You can also use the first few articles in this series to setup a PostgreSQL instance for use with any other programming language. There is nothing specific about this install that limits it to being used with Go.
In order to achieve this, we will start off by walking through the installation and setup process of Postgres, followed by a brief overview of using
psql to interact with PostgreSQL.
After that we will start connecting to our database using Go and the database/sql package and writing raw SQL. This is intended to give you enough knowledge to move forward with writing your own SQL integration in your Go code if you choose to.
Next, we will discuss ORMs, which are tools that help us convert data between our application types and the records stored inside of a PostgreSQL database. While it isn’t required to use an ORM to develop applications that interact with PostgreSQL, I find it valuable to discuss the pros and cons of using an ORM vs writing your own code, especially for beginners.
Finally, we will dive into ORMs in more detail. Specifically, we will be using GORM to create a model layer for an application, and in future posts I might also explore a few other ORMs if there is enough demand. (Hint: Email me - email@example.com if you want me to do this!)
The series currently has (or is expected to have) the following articles in it:
Installing Postgres is specific to your operating system, so this section is broken into three different posts. Each of these posts will guide you on how to install PostgreSQL 9.5 and will also give you guidance on how to connect to your Postgres instance using a role.
This section will be composed of roughly three articles, but may be expanded over time.
These four should be read in the order presented unless you are already familiar with SQL.
This section is again composed of several articles and could be expanded over time, but for now it is three articles that should be read in the order presented here unless you are somewhat familiar with Go & PostgreSQL.
Learn how to use ORMs made available by the Go community to interact with your PostgreSQL database.
This section is an idea that I would like to explore in the future, but as of now there aren’t any articles written.
If you have any suggestions on what other articles would compliment this series please reach out and let me know - firstname.lastname@example.org. I am always open to suggestions for new posts 😀
The article titles listed here are mostly tentative and might be changed as I write the articles. My goal is to cover all of the subjects mentioned, but this might require me to create more or less articles than I originally intended.
Want to be updated when I release new articles in this series? Sign up for my mailing list and I will send you an email when new posts are released!
Getting started with SQL in Go can be tricky. How do you design your code so that it is testable? How do you make your database connections available in your http handlers?
In my course, Web Development with Go, we use the SQL database in a real web application and cover all of these details in more. You will learn how to properly build a robust, testable database layer and how to make it available to your http handlers.
If you sign up for my mailing list (down there ↓over there →) I'll send you a FREE sample so you can see if it is for you. The sample includes over 2.5 hours of screencasts and the first three chapters from the book.
You will also receive notifications when I release new articles, along with other freebies that I only share with my mailing list.
Jon Calhoun is a full stack web developer who also teaches about Go, web development, algorithms, and anything programming related. He also consults for other companies who have development needs. (If you need some development work done, get in touch!)
Jon is a co-founder of EasyPost, a shipping API that many fortune 500 companies use to power their shipping infrastructure, and prior to founding EasyPost he worked at google as a software engineer.
Spread the word
Did you find this page helpful? Let others know about it!
Sharing helps me continue to create both free and premium Go resources.
Want to discuss the article?
©2018 Jonathan Calhoun. All rights reserved.