CRUD Operations क्या हैं
CRUD का मतलब है create, read, update, delete: वे चार चीज़ें जो हर app stored data के साथ करती है।
In this page:
CRUD Operations
CRUD को एक छोटी data layer में wrap करें ताकि routes simple रहें। चाहे database कोई भी हो, operations same ideas हैं: एक record insert करना, records query करना, एक record बदलना, और एक remove करना। Meaningful results return करें और not-found cases handle करें।
Note:
Database code को एक module में रखें ताकि आप बाद में database swap कर सकें।
उदाहरण: CRUD operations
class Store {
constructor() { this.rows = new Map(); this.next = 1; }
create(data) { const row = { id: this.next++, ...data }; this.rows.set(row.id, row); return row; }
read(id) { return this.rows.get(id) || null; }
update(id, patch) { const r = this.read(id); if (!r) return null; Object.assign(r, patch); return r; }
remove(id) { return this.rows.delete(id); }
}
const s = new Store();
const u = s.create({ name: "Ada" });
console.log(s.read(u.id));
console.log(s.update(u.id, { name: "Ada L." }));
console.log(s.remove(u.id), s.read(u.id));
// Output:
// { id: 1, name: 'Ada' }
// { id: 1, name: 'Ada L.' }
// true null
⚠️ Run this in your own terminal or Node.js environment.
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- route handlers के आर-पार queries scatter करना
- missing records handle न करना
- input validate करना भूल जाना
चैप्टर सारांश
- Create, read, update, delete operations होते हैं
- Data access को एक layer में रखें
- Not found handle करें
- Input validate करें
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: