Sikau

Prisma · Day 10 · about 45 min

Project: Blog data layer

Users, posts and tags with relation queries and nested writes.

A blog's repository

Build the data functions a blog's pages call: the feed, tag pages, writing a post with tags, and publishing.

A data layer of small functions

This project brings the relations unit together. Every function uses at least one idea from it — relation filters, nested writes, connectOrCreate or include — so finishing it is good evidence you've understood how Prisma models connected data.

Pages shouldn't build Prisma queries themselves. Instead, write a small data layer: one function per need, each with a clear name and return type. The feed page calls feed(), the tag page calls tagged(name), the editor calls writePost(...). When a query changes, you change one function, and every page keeps working.

  • feed() — published posts, newest first, with author names.
  • tagged(name) — post titles filtered through the PostTag join model.
  • writePost(authorId, title, tags) — a nested create with connectOrCreate tags.
  • publish(id) — flip a flag; throw a clear error if the post doesn't exist.

Return plain, page-ready values (like formatted strings or small objects) rather than raw records with every field.

The rest of this lesson

  • Writing a post with tagsexplain
  • Errors worth handlingexplain
  • Function to Prisma featurematch
  • Order of a nested post writeorder
  • Blog functionschallenge
  • Badge quizquiz
  • Unit 2 complete!recap

Continue this lesson free — run real code in your browser

Continue with Google

See all 15 lessons of Prisma