typescriptintermediate
Prisma Find with Relations
Query related records using Prisma ORM include and select for efficient nested data loading.
typescriptPress ⌘/Ctrl + Shift + C to copy
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
export async function getUserWithPosts(userId: string) {
return prisma.user.findUnique({
where: { id: userId },
include: {
posts: {
where: { published: true },
orderBy: { createdAt: 'desc' },
take: 10,
select: {
id: true,
title: true,
slug: true,
createdAt: true,
_count: { select: { comments: true } },
},
},
profile: true,
},
});
}Sponsored
Try Prisma Accelerate — Global Database Cache
Use Cases
- Loading user profiles with posts
- Querying orders with line items
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
javaintermediate
JPA Entity Mapping with Relationships
Map entities with JPA annotations: OneToMany, ManyToOne, ManyToMany with fetch strategies and cascading.
Best for: Database schema design with JPA entities
#jpa#spring-data
scalaintermediate
Database Queries with Slick
Write type-safe database queries with Slick: table definitions, CRUD, joins, and streaming.
Best for: Type-safe database access
#scala#slick
typescriptintermediate
Cursor-Based Pagination API
Implement cursor-based pagination with forward/backward navigation, consistent ordering, and link headers.
Best for: REST API pagination
#nodejs#pagination
typescriptadvanced
Data Caching with unstable_cache
Cache database queries and expensive computations with unstable_cache for server-side memoization.
Best for: database query caching
#nextjs#cache