CodingNic

Data Layer & Home List

Setting Up the Data Layer

Data Layer & Home List 5 min read

Setting Up the Data Layer

Setting Up the Data Layer

Right now, nothing in this app talks to the database. In this module you’ll
build the foundation everything else sits on:

  • lib/db.ts — a single, reused Postgres connection pool
  • lib/types.ts — the TypeScript shape of a Contact
  • lib/contacts.ts — your first query function, getContacts
  • lib/utils.ts — small presentation helpers (initials, alphabet grouping)
  • The Home page, actually rendering contacts from the database

Since the starter has no sample data yet, you’ll insert a few test rows by
hand with psql so there’s something to see. (A proper, repeatable seed
script is its own feature — you’ll build that in Module 10.)

By the end of this module, the Home page will show real contacts, grouped
alphabetically, pulled live from Postgres.