Script Valley
REST API Development: Beginner to Production
Database Integration with PostgreSQL and Prisma/Assessment

Practice & Assessment

Test your understanding of Database Integration with PostgreSQL and Prisma

Multiple Choice Questions

5
1

Why should PrismaClient be instantiated as a singleton rather than creating a new instance in each module?

2

What does `select` do in a Prisma query and why is it important for API security?

3

An API fetches 50 blog posts and their authors. Without eager loading, how many database queries does this likely produce?

4

Why should you use `prisma migrate deploy` instead of `prisma migrate dev` in production deployments?

5

Inside a Prisma interactive transaction, what happens if you throw an error?

Coding Challenges

1
1

Build a posts API with Prisma and PostgreSQL

Using a local PostgreSQL database: 1) Create a Prisma schema with User (id, email, name, createdAt) and Post (id, title, content, published boolean default false, authorId FK, createdAt). Run migrations. 2) Seed 3 users and 10 posts (mix of published/draft). 3) Implement: GET /posts?published=true&authorId=1 (with eager-loaded author name), POST /posts (create with authorId in body), PATCH /posts/:id (update title, content, or published), DELETE /posts/:id. 4) All endpoints must use the PrismaClient singleton. Test with curl. Time estimate: 30 minutes.

Medium

Mini Project

1

E-Commerce API with PostgreSQL

Build an e-commerce REST API backed by PostgreSQL via Prisma. Schema: User, Product (id, name, price, stock, categoryId), Category, Order (id, userId, status, totalAmount, createdAt), OrderItem (orderId, productId, quantity, unitPrice). Endpoints: full CRUD for /products and /categories, GET /products?category=&minPrice=&maxPrice=&inStock=true with eager-loaded category. POST /orders โ€” creates order and all OrderItems in a single Prisma transaction; decrement stock for each product, throw if any product is out of stock. GET /orders/:id with items and product names. PATCH /orders/:id/status (admin only). All responses use select to exclude internal fields. Include at least two database migrations (initial schema, then add a description field to Product).

Hard
Practice & Assessment โ€” Database Integration with PostgreSQL and Prisma โ€” REST API Development: Beginner to Production โ€” Script Valley โ€” Script Valley