Backend development

Stage 2 · Lesson 9 of 11

database/sql, pgx or sqlc

Relational databases and SQL

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

Practise

Also worth your time

Mark this stage as not done?