Day 098 — Week 2 Review + Recall¶
Month 4 · Week 2 · ⬅ Day 097 · Day 099 ➡ · Journal index
🎯 Learning Objective¶
Consolidate the Week 2 data-access stack — database/sql → pgx/pgxpool → sqlc → golang-migrate → repository pattern → transactions — with closed-book recall, and capture what's still fuzzy.
📚 Topics¶
- Connecting & pooling (
database/sql,pgxpool) - Type-safe queries (sqlc) and schema versioning (golang-migrate)
- Structuring access: repository pattern + transactions/context
📖 Reading / Sources¶
- Re-skimmed this week's day notes 092–097
-
database/sql· pgxpool · sqlc docs · golang-migrate
📝 Notes¶
- Full write-up lives in the week review → Week 2 review.
- The mental model that ties it together: migrate owns the schema (DDL), sqlc turns SQL into typed Go, pgx/pgxpool runs it over a pool, the repository hides all of it behind a domain interface, and transactions make multi-step writes atomic — all threaded with context.
💻 Code Examples¶
No new code today — re-ran this week's runnable examples to check recall:
go run ./examples/month-04/pool
go run ./examples/month-04/migrate
go run ./examples/month-04/repository
go run ./examples/month-04/txn
go test ./exercises/month-04/week-2/...
🏋️ Exercises / Practice¶
| Exercise | Status | Link |
|---|---|---|
| Re-solve all Week 2 exercises closed-book | ✅ | exercises/month-04/week-2 |
🐛 Mistakes Made¶
- On recall I first said
sql.Openconnects — it doesn't. Re-anchored on "lazy; Ping to verify".
❓ Open Questions¶
- Carried into the week review's action items (serialization retries, PgBouncer, dynamic SQL with sqlc).
🧠 Active Recall (answer without looking)¶
- Q: Name the five layers of this week's data-access stack and what each owns.
A
golang-migrate (schema/DDL) → sqlc (type-safe SQL→Go) → pgx/pgxpool (driver + connection pool) → repository (domain interface hiding storage) → transactions+context (atomic, cancellable writes).- Q: What's the one-line rule for safe transactions in Go?
A
`defer tx.Rollback()` immediately after `BeginTx` (it no-ops after a successful `Commit`), run statements on `tx`, propagate `ctx`, and check `Commit`'s error.🪶 Feynman Reflection¶
This week was about everything behind the HTTP handler from Week 1: how a request reaches durable storage safely. The handler asks a repository; the repository runs typed queries through a pooled connection, optionally inside a transaction; the schema those queries assume is itself version-controlled by migrations. Each layer hides the one below it.
🕳️ Knowledge Gaps¶
- Production concerns: serialization-failure retries, connection poolers, zero-downtime schema changes — flagged for next week's deeper service work.
✅ Summary¶
Week 2 done: I can connect, pool, query type-safely, migrate the schema, structure access behind a repository, and write atomic context-aware transactions.
⏭️ Next Steps / Prep for Tomorrow¶
- Week 3: putting it together into a service — config, logging/observability, and testing the data layer.
| Time spent | Difficulty | Confidence |
|---|---|---|
| 60 min | 🟦⬜⬜⬜⬜ | 🟦🟦🟦🟦⬜ |
Suggested commit: docs(journal): month 4 week 2 review + recall (day 098)