Go (Golang) and Databases: A Practical Guide
300 pages
English
PDF
4.5

Go (Golang) and Databases: A Practical Guide

Go (Golang) and Databases: A Practical Guide

Author:

Year:

Summary:

The book "Go (Golang) and Databases: A Practical Guide" is a comprehensive resource for developers who want to master the interaction of the Go language with various database management systems. The author, experienced Go developer Alexey Smirnov, shares proven approaches to designing the data access layer, optimizing queries, and building scalable applications.



What is this book about?

The material covers the full cycle of working with databases in Go: from installing drivers and writing the first SQL queries to implementing complex transactions, connection pools, and integration with Redis. Special attention is paid to:

  • Relational Databases — PostgreSQL, MySQL, SQLite: working with database/sql, prepared statements, scanning results, handling NULL values.
  • ORM and Query Builder — detailed analysis of GORM, Ent, and sqlx: when to use ORM and when to use pure SQL.
  • Schema Migrations — managing database versions using golang-migrate and goose.
  • Transactions and Concurrency — isolation, locks, error handling in goroutines.
  • NoSQL and Caching — Redis: data structures, pub/sub, TTL, implementing a cache.
  • Testing and Benchmarks — mock objects, test databases, query profiling.
  • Best Practices — connection pools, retries, graceful shutdown, protection against SQL injection.


Who is this book for?

  • Go developers of any level — from Junior to Senior, looking to deepen their knowledge of working with data.
  • Backend engineers transitioning to Go from other languages (Python, Java, C#).
  • Architects and team leads choosing optimal solutions for data storage.
  • Students and interns learning modern Go development.


What will you learn after reading?

  • How to properly configure a database connection and manage a connection pool.
  • How to write efficient SQL queries and avoid the N+1 problem.
  • How to design a database schema considering Go specifics (structs, interfaces).
  • How to implement migrations and rollbacks without data loss.
  • How to test code that works with a database using mocks and integration tests.
  • How to integrate Redis for caching and queues.
  • How to optimize performance: indexes, explain, batch inserts.


The book contains dozens of ready-made code examples that can be immediately applied in real projects. All examples are available in the GitHub repository and have been tested on Go 1.21+.



Ideal for those who want not just to "make the code work," but to write reliable, fast, and maintainable applications in Go.



Download the book on PythonLib and start working professionally with databases in Go today!

Recommendations