Stage 2 · Lesson 9 of 11
database/sql, pgx or sqlc
Go backends usually talk to with little or no ORM. database/sql is the standard interface. Its sql.DB is a , a set of open connections that queries share.
QueryContext returns rows that you scan into structs. like $1 keep values out of the SQL text, which protects you from . pgx is the PostgreSQL driver most projects use, directly or through database/sql. sqlc goes further.
You write plain SQL queries in a file, and it generates Go functions for them. Queries stay visible, and the compiler checks the types. Always pass a context, so queries respect timeouts.
Common trapforgetting rows.Close() or rows.Err() after a loop; unclosed rows hold on to a connection until the pool runs dry.
A question to check yourself, an AI practice session and 2 cheat sheet entries come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking Relational Database Design and Modeling
Design Gurus · Intermediate · $98 one-time
The modelling and normalisation decisions that stay with a codebase for years
- CourseFreeCS50's Introduction to Databases with SQL
Harvard University · Beginner
Free course from querying through schema design, indexes, transactions and scaling
Practise
Also worth your time
- Database Indexing Explained: B-Tree, Hash, Bitmap, R-Tree, and When to Use Each (opens in a new tab)Read
B-tree and composite indexes, plus the leftmost-prefix rule that trips people up
What sits under your queries: storage engines, transactions and isolation levels