Book 2 · Lesson 2.5

PostgreSQL and SQLx

  • Read team_events and team_metrics schema
  • Explain why analyzer owns writes
  • Connect SQLx to compile-time query checking

Prerequisites: 2.4

Kafka is the stream; Postgres is the system of record for dashboard queries.

Schema

PostgresSchemaDiagram mirrors infra/docker/init-db.sql:

TablePurpose
team_eventsEnriched events with sentiment, risk_score
team_metricsRolled-up KPIs for cards

SQLx in analyzer

Queries are checked at compile time against the schema — typos fail CI, not production.

INSERT INTO team_events (id, source, payload_json, sentiment, risk_score)
VALUES ($1, $2, $3, $4, $5);

Teach-back prompt

Why not query Kafka directly from the dashboard?

Team metrics schema

Lesson 2.5 check

1. team_metrics stores…