Performance: CRUD with Prisma
This concept affects server response time and database query efficiency, impacting how fast the page can load or update data.
async findAll(page = 1, limit = 10) { return await this.prisma.user.findMany({ skip: (page - 1) * limit, take: limit }); }
async findAll() { return await this.prisma.user.findMany(); }
| Pattern | Database Queries | Server Response Time | Network Payload | Verdict |
|---|---|---|---|---|
| Fetch all without pagination | 1 large query | High due to large data | Large JSON payload | [X] Bad |
| Fetch with pagination | 1 small query | Low and predictable | Small JSON payload | [OK] Good |
| Update with read then update | 2 queries | Higher latency | Minimal payload | [X] Bad |
| Update with single query | 1 query | Lower latency | Minimal payload | [OK] Good |
| Delete with read then delete | 2 queries | Higher latency | Minimal payload | [X] Bad |
| Delete with single query | 1 query | Lower latency | Minimal payload | [OK] Good |
create to add, findMany to get multiple records, update to change, and delete to remove records.findMany is specifically designed to fetch many records from the database.create method is used to add new records in Prisma.this.prisma.user.create({ data: { ... } }) where data holds the new record's fields.this.prisma.user.update({ where: { id: 5 }, data: { email: 'new@example.com' } })update method requires a where clause to find the record and data to specify changes.id: 5 and changes the email field to 'new@example.com'.this.prisma.user.delete({ data: { id: 3 } })delete method requires a where clause to specify which record to remove.data instead of where, causing a syntax error.upsert method updates a record if it exists or creates it if not, combining both actions safely.upsert with where to find the user, update for changes, and create for new record is the best practice.Pass the test and this pattern moves unknown