Ravindra BagaleCourses & study guidesTrack your progress

Chapter 05 · AI-Powered Full Stack

Database Basics for Full Stack (Postgres)

AI answers improve when grounded in your FAQ rows. Postgres is the beginner default.

~4 min readBeginner

Why this matters

Without a database, every answer is generic. With a small FAQ table, your API can fetch relevant rows before calling AI (RAG lite in a later chapter). Postgres is free to run locally and common in India job posts.

What you will learn

You will run Postgres (Docker or local install), create a faqs table, seed three India shop FAQs, and read them from the API.

How to do it

Use official Postgres docs for install. We do not recommend pirated tools. Connection string stays in .env.

Steps (do these in order)

  1. Step 1 — Run Postgres. Docker example: postgres:16 with a volume. Or install Postgres locally. Create database shopfaq.
  2. Step 2 — Create table. CREATE TABLE faqs (id serial PRIMARY KEY, question text NOT NULL, answer text NOT NULL, updated_at timestamptz default now());
  3. Step 3 — Seed three rows. Delivery in Pune / COD rules / 7-day return — fictional store names only.
  4. Step 4 — Read from API. Add GET /api/faqs that returns all rows as JSON. Confirm from the browser or curl.
  5. Step 5 — Prepare for AI. In /api/ask, optionally SELECT question, answer FROM faqs LIMIT 20 and keep them ready for chapter 6–7.

Practice

  • Export a faqs.csv backup of your three rows.
  • Write the DATABASE_URL shape in .env.example without a real password.