← Back to Node.js Course | Chapter 9: Database Integration | Lesson 7 of 7

CRUD Operations क्या हैं

CRUD का मतलब है create, read, update, delete: वे चार चीज़ें जो हर app stored data के साथ करती है।

In this page:

  1. CRUD Operations

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

javascript
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. #}
आम गलतियां
  1. route handlers के आर-पार queries scatter करना
  2. missing records handle न करना
  3. 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:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.