Go (Golang) and Databases: A Practical Guide
Go (Golang) and Databases: A Practical Guide
Summary:
This book is a comprehensive practical guide to working with databases in the Go (Golang) language. It covers all stages: from installing drivers and creating the first connection to optimizing complex queries and designing data schemas.
What the book is about
- Basics of working with SQL from Go: connecting to SQLite, MySQL, PostgreSQL, executing queries, working with prepared statements.
- ORMs and Query Builders: an overview of popular libraries (GORM, sqlx, Ent), their comparison, and choosing the right one for the task.
- Transactions and Concurrency: managing transactions, error handling, working with connection pools.
- Migrations and Schema Versioning: tools (golang-migrate, goose), writing migrations, rolling back changes.
- Advanced Topics: query caching, working with NoSQL (MongoDB, Redis), Repository and Unit of Work patterns.
- Testing: mocking the database, integration tests, benchmarks.
Who this book is for
The book is suitable for both beginner developers just getting acquainted with Go and experienced programmers looking to deepen their knowledge of working with databases. A basic knowledge of Go syntax is assumed, but all concepts are explained from the ground up.
What you will learn
- How to design efficient data schemas for Go applications.
- How to avoid common mistakes when working with SQL (race conditions, connection leaks, N+1 problem).
- How to choose the right approach: pure SQL, ORM, or Query Builder.
- How to write safe and performant queries.
- How to integrate databases into Go web services (REST API, microservices).
- How to test code that works with a database and automate migrations.
All code examples are accompanied by detailed comments and are ready to be used in real projects. The book is structured from simple to complex, allowing you to immediately apply the knowledge you gain in practice.
This is not just a reference guide, but a full-fledged textbook that will help you become a confident developer capable of creating reliable and scalable systems in Go with any database.
Recommendations
Web Development in Go (Golang): From Basics to Deployment
Kotlin for Data Science: Data Analysis and Machine Learning
Machine Learning in C# (.NET): From Basics to Production
Professional TypeScript: Advanced Techniques
Fundamentals of iOS 15 Programming with Swift
Android Programming with Kotlin for Beginners