Thuta Learning
How Databases Work
IntermediateData & Databasesbeginner

SQLite နှင့် Embedded Database များ

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • SQLite နှင့် Embedded Database များ concept ကို နားလည်ရှင်းပြနိုင်ရန်
  • Diagram/table ကို ဖတ်ပြီး data model/schema/architecture ဘယ်လို ပုံသဏ္ဌာန်ရှိသလဲ ခြေရာခံနိုင်ရန်
  • ကိုယ့် project အတွက် database concept/system ကို ဘယ်လို အသုံးချသင့်သလဲ ရှင်းပြနိုင်ရန်

နားလည်ထားရမယ့် အချက်

SQLite ဆိုတာ embedded relational database တစ်ခုပါ - server process သီးခြား မဟုတ်ဘဲ application ထဲကို link လုပ်ထားတဲ့ library တစ်ခုအနေနှင့် disk ပေါ်က file တစ်ခုကို ဖတ်/ရေးပါတယ်။

Application

Application code က SQLite library ကို ခေါ်ပါတယ်

SQLite Library

Application process ထဲမှာပဲ run ပြီး query တွေကို ကိုင်တွယ်ပါတယ်

Database File

Disk ပေါ်က ordinary file တစ်ခုကို တိုက်ရိုက် ဖတ်/ရေးပါတယ် - server မလိုပါ

  • Mobile app local storage
  • Desktop application
  • Command-line tool ငယ်များ
  • Local development / automated test
  • Edge / offline-first scenario

PostgreSQL/MySQL လို server database ကတော့ ကိုယ်ပိုင် long-lived process အနေနှင့် run ပြီး applications တွေက client အနေနှင့် network ကတစ်ဆင့် ချိတ်ဆက်ပါတယ် - multi-user, production-scale workload အတွက် ဆောက်ထားပါတယ်။

Absolute claim ကို ရှောင်ပါ

"SQLite က real workload တွေကို မကိုင်တွယ်နိုင်ဘူး" လို့ မပြောပါနှင့် - modern SQLite architecture တွေက genuinely sophisticated ဖြစ်လာခဲ့ပါတယ်၊ ရွေးချယ်မှုက concurrency/deployment လိုအပ်ချက်ပေါ်သာ မူတည်ပါတယ်။

Embedded Database
Application ထဲကို library အနေနှင့် တိုက်ရိုက် link လုပ်ထားပြီး၊ သီးခြား server process မလိုဘဲ same process ထဲမှာပဲ data ကို ဖတ်/ရေးသည့် database တစ်မျိုး။
text
EMBEDDED VS SERVER DATABASE MODEL
---------------------------------
EMBEDDED (SQLite)
Application -> SQLite Library -> Database File
              (in-process, single file, no server)

SERVER (PostgreSQL / MySQL)
Application -> Network -> Database Server -> Disk
              (separate process, many clients connect)

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

Application ကိုယ်တိုင်ကသာ local storage ပိုင်ဆိုင်ပြီး တစ်ချိန်တည်း concurrent access မလိုအပ်ရင် SQLite ကို ရွေးပါ - mobile local cache, desktop setting, ဒါမှမဟုတ် test suite တစ်ခုမျိုးမှာပါ။

Independent application/service/user များစွာက network ကတစ်ဆင့် data တစ်ခုတည်းကို concurrent ဖတ်/ရေးဖို့ လိုအပ်ရင် PostgreSQL/MySQL လို server database ကို ရွေးပါ။

Project တချို့က ကြားအလယ်မှာ ရှိတတ်ပါတယ် - SQLite နှင့် စတင်ပြီး concurrent access တကယ်လိုအပ်လာမှသာ migrate လုပ်တာလည်း ရပါတယ်။

အောက်က runnable ဥပမာက application need ကို ယူပြီး embedded ဒါမှမဟုတ် server-based starting point ကို အကြံပြုပါတယ်။

အတူတူ စမ်းရေးကြည့်မယ်

javascript
function suggestDatabaseArchitecture(profile) {
  const {
    isMobileOrDesktopApp,
    needsMultipleConcurrentWriters,
    needsNetworkAccess,
    isSimpleLocalTool,
  } = profile;

  if (needsMultipleConcurrentWriters || needsNetworkAccess) {
    return "Server-based database (e.g., PostgreSQL/MySQL) - a reasonable starting point.";
  }
  if (isMobileOrDesktopApp || isSimpleLocalTool) {
    return "Embedded database (e.g., SQLite) - a reasonable starting point.";
  }
  return "Depends on further requirements - consider concurrency and deployment model.";
}

console.log("Mobile note-taking app:", suggestDatabaseArchitecture({
  isMobileOrDesktopApp: true, needsMultipleConcurrentWriters: false,
  needsNetworkAccess: false, isSimpleLocalTool: false,
}));

console.log("Multi-user SaaS backend:", suggestDatabaseArchitecture({
  isMobileOrDesktopApp: false, needsMultipleConcurrentWriters: true,
  needsNetworkAccess: true, isSimpleLocalTool: false,
}));

console.log("Local CLI test fixture:", suggestDatabaseArchitecture({
  isMobileOrDesktopApp: false, needsMultipleConcurrentWriters: false,
  needsNetworkAccess: false, isSimpleLocalTool: true,
}));
You should see
Mobile note-taking app: Embedded database (e.g., SQLite) - a reasonable starting point.
Multi-user SaaS backend: Server-based database (e.g., PostgreSQL/MySQL) - a reasonable starting point.
Local CLI test fixture: Embedded database (e.g., SQLite) - a reasonable starting point.

Mobile app နှင့် local test fixture နှစ်ခုစလုံးက embedded အဖြေရသလို၊ concurrent writer/network access လိုအပ်တဲ့ SaaS backend ကတော့ server-based အဖြေရပါတယ်။

၅ မိနစ် စမ်းကြည့်

suggestDatabaseArchitecture ကို isReadHeavyAnalytics flag တစ်ခု ထပ်ထည့်ပြီး၊ true ဖြစ်ရင် server-based database ကို အကြံပြုအောင် ချဲ့ကြည့်ပါ။

သတိလေးတစ်ချက်

"SQLite က real workload မကိုင်တွယ်နိုင်ဘူး" လို့ blanket rule အဖြစ် ယုံကြည်ခြင်း

Multiple process/machine က data တစ်ခုတည်းကို concurrent ရေးရမယ့်အခါမှာပါ SQLite ကို ရွေးချယ်ခြင်း

SQLite: About SQLiteHow Databases Work

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • "SQLite က real workload မကိုင်တွယ်နိုင်ဘူး" လို့ blanket rule အဖြစ် ယုံကြည်ခြင်း
  • Multiple process/machine က data တစ်ခုတည်းကို concurrent ရေးရမယ့်အခါမှာပါ SQLite ကို ရွေးချယ်ခြင်း
  • ဒီ course က database concept/landscape ကို framework-neutral level မှာသာ သင်ပေးပါတယ် — SQL syntax, PostgreSQL, MongoDB, Redis ကို နက်နက်ရှိုင်းရှိုင်း လေ့လာချင်ရင် SQL, PostgreSQL, MongoDB, Redis tutorial တွေဆီ ဆက်သွားပါ။

လေ့ကျင့်ခန်း

suggestDatabaseArchitecture ကို isReadHeavyAnalytics flag တစ်ခု ထပ်ထည့်ပြီး၊ true ဖြစ်ရင် server-based database ကို အကြံပြုအောင် ချဲ့ကြည့်ပါ။

You'll know it worked when: Mobile note-taking app: Embedded database (e.g., SQLite) - a reasonable starting point. Multi-user SaaS backend: Server-based database (e.g., PostgreSQL/MySQL) - a reasonable starting point. Local CLI test fixture: Embedded database (e.g., SQLite) - a reasonable starting point. Mobile app နှင့် local test fixture နှစ်ခုစလုံးက embedded အဖြေရသလို၊ concurrent writer/network access လိုအပ်တဲ့ SaaS backend ကတော့ server-based အဖြေရပါတယ်။

SQLite နှင့် Embedded Database များ | Thuta Learning