Go (Golang) and Databases: A Practical Guide
Go (Golang) and Databases: A Practical Guide
Summary:
The book "Go (Golang) and Databases: A Practical Guide" is a comprehensive textbook for developers who want to master interacting with modern database management systems using the Go language. The author guides the reader step by step from the basics of SQL and driver installation to complex scenarios: connection pools, ACID transactions, schema migrations, and working with NoSQL solutions.
The book consists of three parts:
- SQL Basics — setting up PostgreSQL and MySQL, executing queries via
database/sql, preparing parameterized queries to protect against SQL injection. - Advanced Techniques — transactions, isolation, connection pools, ORM libraries (GORM, Ent), and migrations with
gooseandgolang-migrate. - NoSQL and Non-Standard Databases — MongoDB (
mongo-go-driverdriver), Redis (caching, Pub/Sub), and SQLite for embedded solutions.
You will learn:
- How to design data schemas and write efficient queries in Go.
- How to handle errors and manage connections in a concurrent environment.
- How to perform migrations without data loss and test code with databases.
- How to integrate Redis for caching and queues.
- How to optimize performance: indexes, EXPLAIN, connection pools.
The book is suitable for both beginner Go developers who already know the language syntax but have not worked with databases, and experienced engineers who want to systematize their knowledge and master modern approaches (e.g., the Repository pattern, context-based transactions).
All examples are accompanied by working code that can be downloaded from GitHub. Special attention is given to security (preventing SQL injection, handling timeouts) and testing (mocks, integration tests with test databases).
If you write web services, microservices, or CLI tools in Go, this book will become your desktop reference for working with data.