Blog
Jan 4, 2025
Storing and Querying Relational Data with Prisma in a SvelteKit App
Discover how conducting user research can inform design decisions and lead to better user satisfaction.
Isaque Ferreira
Modern web applications often require the ability to manage and interact with complex relational data — whether for handling users, organizations, events, or various forms of user interactions. This article demonstrates how to efficiently store and query relational data using Prisma ORM within a SvelteKit application.
The structure and patterns shown here are ideal for apps such as church platforms, event management systems, or any solution that depends on scalable, well-structured data relationships.
Use Case Example: Church Platform
To make it practical, let’s say I’m building a basic structure for a church management system:
User: a person who logs into the app
Church: an organization that users belong to
Event: something the church hosts (like a service or meeting)
Attendance: a record of users attending events
Step 1: Setting Up Prisma in SvelteKit:

Then I create a helper to access Prisma in src/lib/server/prisma.ts
:

Step 2: Define the Prisma Schema
In prisma/schema.prisma, I define the models like this:

Then I run the migration:npx prisma migrate dev --name init
Step 3: Seeding Some Data (Optional)
For quick testing, I seed the database with a script:

Run it with:
Step 4: Querying Relational Data in the App:
In src/routes/dashboard/+page.server.ts
, I fetch the data like this:
And in the page component (+page.svelte
):
Why I Use This Setup
This structure lets me:
Keep data normalized and fast to query
Easily show nested data in the UI
Handle complex logic like filtering attendances or grouping events by church
Maintain clean code with Prisma’s type safety
Whether I’m building an app for a church, a client, or an internal tool, SvelteKit + Prisma helps me move fast while staying organized.