Chapter 6. Storing data

 

This chapter covers

  • In-memory storage with structs
  • File storage with CSV and gob binary files
  • Relational database storage with SQL
  • Go and SQL mappers

We introduced data persistence in chapter 2, briefly touching on how to persist data into a relational database, PostgreSQL. In this chapter we’ll delve deeper into data persistence and talk about how you can store data in memory, files, relational databases, and NoSQL databases.

Data persistence is technically not part of web application programming, but it’s often considered the third pillar of any web application—the other two pillars are templates and handlers. This is because most web applications need to store data in one form or another.

I’m generalizing but here are the places where you can store data:

  • In memory (while the program is running)
  • In files on the filesystem
  • In a database, fronted by a server program

In this chapter, we’ll go through how Go can be used to access data (create, retrieve, update, and delete—better known as CRUD) in all these places.

6.1. In-memory storage

In-memory storage refers not to storing data in in-memory databases but in the running application itself, to be used while the application is running. In-memory data is usually stored in data structures, and for Go, this primarily means with arrays, slices, maps, and most importantly, structs.

6.2. File storage

 
 
 
 

6.3. Go and SQL

 
 
 

6.4. Go and SQL relationships

 
 
 

6.5. Go relational mappers

 
 

6.6. Summary

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage