prisma-patterns
यह क्या करती है
यह गाइड आपके प्रोग्रामिंग प्रोजेक्ट में Prisma ORM का बेहतर इस्तेमाल करने में मदद करती है। इसमें डेटा को व्यवस्थित करने, तेज़ queries लिखने और आम गलतियों से बचने के अच्छे तरीके बताए गए हैं।
कब इस्तेमाल करें
- ✓Prisma से डेटाबेस का ढाँचा बनाते या बदलते समय।
- ✓ऐसा कोड लिखते समय जो डेटाबेस से जानकारी लाता या सहेजता है।
- ✓transactions में गलतियाँ ठीक करते समय, या एक साथ बहुत सारा डेटा अपडेट करते समय।
Skill का लिंक
https://github.com/affaan-m/ECC/blob/main/pi/core/skills/prisma-patterns/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मैं कैसे सुनिश्चित करूँ कि मेरी database queries तेज़ और सुरक्षित हों?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
यह गाइड बताती है कि डेटाबेस कैसे सेट करें, डेटा लाने के सबसे अच्छे तरीके कैसे चुनें और transactions को सुरक्षित तरीके से कैसे इस्तेमाल करें। यह उन आम जालों के बारे में भी चेतावनी देती है जिनसे धीमापन या गलतियाँ आ सकती हैं।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Prisma Patterns
Production patterns and non-obvious traps for Prisma ORM in TypeScript backends.
Check your version before applying patterns. The Prisma API surface has evolved across major releases:
npx prisma --versionNotable API differences across versions:
relationJoinscan load relations via JOIN rather than separate queries, but may cause row explosion on large 1:N relations or deepinclude— benchmark both approachesomitfield modifier andprisma.$extendsClient Extensions API were added- Newer installs: the package may be named
prismainstead of@prisma/client;PrismaClientmay require a driver adapter (e.g.@prisma/adapter-pg);datasource.urlmay live inprisma.config.tsinstead ofschema.prisma- CLI commands (
migrate dev,migrate deploy,generate) are unchanged across versions
When to Activate
- Designing or modifying Prisma schema models and relations
- Writing queries, transactions, or pagination logic
- Using
updateMany,deleteMany, or any bulk operation - Running or planning database migrations
- Deploying to serverless environments (Vercel, Lambda, Cloudflare Workers)
- Implementing soft delete or multi-tenant row filtering
Core Concepts
ID Strategy
| Strategy | Use When | Avoid When |
|---|---|---|
@default(cuid()) |
Default choice — URL-safe, sortable, no collisions | Sequential IDs needed for external systems |
@default(uuid()) |
Interoperability with non-Prisma systems required | High-write tables (random UUIDs fragment B-tree indexes) |
@default(autoincrement()) |
Internal join tables, audit logs | Public-facing IDs (exposes record count) |
Schema Defaults
model User {
id String @id @default(cuid())
email String @unique // @unique already creates an index — no @@index needed
name String
role Role @default(USER)
posts Post[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
@@index([createdAt])
@@index([deletedAt, createdAt]) // composite for soft-delete + sort queries
}
- Add
@@indexon every foreign key and column used inWHEREorORDER BY. - Declare
deletedAt DateTime?upfront when soft delete is a foreseeable requirement — adding it later requires a migration on a live table. updatedAt @updatedAtis set automatically by Prisma onupdateandupsertonly (see Anti-Patterns for bulk update trap).
include vs select
include |
select |
|
|---|---|---|
| Returns | All scalar fields + specified relations | Only specified fields |
| Use when | You need most fields plus a relation | Hot paths, large tables, avoiding over-fetch |
| Performance | May over-fetch on wide tables | Minimal payload, faster on large datasets |
| Prisma 5 note | Uses JOIN by default (relationJoins) |
Same |
// include — all columns + relation
const user = await prisma.user.findUnique({
where: { id },
include: { posts: { select: { id: true, title: true } } },
});
// select — explicit allowlist
const user = await prisma.user.findUnique({
where: { id },
select: { id: true, email: true, name: true },
});
Never return raw Prisma entities from API responses — map to response DTOs to control exposed fields:
// BAD: leaks passwordHash, deletedAt, internal fields
return await prisma.user.findUniqueOrThrow({ where: { id } });
// GOOD: explicit DTO mapping
const user = await prisma.user.findUniqueOrThrow({ where: { id } });
return { id: user.id, name: user.name, email: user.email };
Transaction Form Selection
| Situation | Use |
|---|---|
| Independent operations, no inter-dependency | Array form |
| Later step depends on earlier result | Interactive form |
| External calls (email, HTTP) involved | Outside transaction entirely |
// Array form — batched in one round trip
const [user, post] = await prisma.$transaction([
prisma.user.update({ where: { id }, data: { name } }),
prisma.post.create({ data: { title, authorId: id } }),
]);
// Interactive form — use tx client only, never the outer prisma client
const post = await prisma.$transaction(async (tx) => {
const user = await tx.user.findUniqueOrThrow({ where: { id } });
if (user.role !== 'ADMIN') throw new Error('Forbidden');
return tx.post.create({ data: { title, authorId: user.id } });
});
PrismaClient Singleton
…
अक्सर पूछे जाने वाले सवाल
Prisma ORM क्या है?
Prisma ORM एक ऐसा टूल है जो प्रोग्रामर्स को डेटाबेस के साथ आसानी और सुरक्षित तरीके से काम करने में मदद करता है, खासकर TypeScript वाले प्रोजेक्ट में।
'patterns' और 'traps' पर ध्यान क्यों दें?
अच्छे patterns अपनाने और जालों से बचने से आपका application तेज़ और स्थिर रहता है, उसमें गलतियाँ कम आती हैं, और बाद में मेंटेनेंस में समय व मेहनत बचती है।
'transactions' क्या होते हैं?
Transactions database operations के एक पैकेट जैसे होते हैं। उस पैकेट के सारे operations या तो सफल होते हैं, या कोई भी नहीं होता, जिससे डेटा की एकरूपता बनी रहती है।
जानकारी
लेखक का मूल विवरण
Prisma ORM patterns for TypeScript backends — schema design, query optimization, transactions, pagination, and critical traps like updateMany returning count not records, $transaction timeouts, migrate dev resetting the DB, @updatedAt skipped on bulk writes, and serverless connection exhaustion. Use when writing a Prisma schema or query, or debugging transactions, migrations, or serverless connect
repo: affaan-m/ECC
लोकप्रियता
- GitHub स्टार
- 280k
- रैंकिंग में स्थान
- #224
- लाइसेंस
- MIT
- अपडेट की गई
- 15/10/2026
कमेंट
- …
इस repository की और skills
accessibility
280kयह आपके एजेंट को ऐसे इंटरफ़ेस बनाने में मदद करता है जिन्हें हर कोई इस्तेमाल कर सके। यह पक्का करता है कि वेबसाइट और ऐप दिव्यांग लोगों के लिए भी अच्छे से काम करें, जैसे नेत्रहीन या जिन्हें चलने-फिरने में दिक्कत होती है।
agent-architecture-audit
280kयह आपके एजेंट को जाँचने देता है कि सब कुछ सही से चल रहा है। यह AI सिस्टम में समस्याएँ ढूँढकर ठीक करता है, ताकि वे उम्मीद के मुताबिक काम करें।
agent-eval
280kयह आपके एजेंट को अलग-अलग AI coding tools की तुलना करने में मदद करता है। यह मापता है कि किसी खास काम के लिए कौन सा टूल ज़्यादा तेज़, सस्ता और भरोसेमंद है।
agent-harness-construction
280kयह आपके एजेंट को काम कैसे करना है, यह बेहतर समझने में मदद करता है। यह उन tools और instructions को बेहतर बनाता है जिनका एजेंट इस्तेमाल करता है, ताकि उसकी सफलता की संभावना बढ़े।
मिलती-जुलती skills
shopify
260kआपके एजेंट को Shopify GraphQL API से स्टोर का डेटा पढ़ने और अपडेट करने देती है, जैसे उत्पाद, स्टॉक, ऑर्डर और ग्राहक।
rest-graphql-debug
260kआपके एजेंट को REST या GraphQL API कॉल क्यों विफल होती है, यह पता करने में मदद करती है, कनेक्शन, लॉगिन, अनुरोध फ़ॉर्मैट और जवाब को एक-एक परत करके जाँचते हुए।
har-derived-api-client
260kआपके एजेंट को किसी वेबसाइट के नेटवर्क ट्रैफ़िक को एक बार रिकॉर्ड करके सीधा API क्लाइंट बनाने देती है, ताकि हर बार पेज पर क्लिक करना न पड़े।