နားလည်ထားရမယ့် အချက်
database သည် user account, product, order, post, message စသော structured data အားလုံး ရှိနေသောနေရာ ဖြစ်သည်။ database မရှိလျှင် app သည် static content ကိုသာ ဆောင်ရွက်နိုင်သည်။
browser ကို database credential တိုက်ရိုက် ဘယ်တော့မှ မပေးပါနှင့်
architecture အစစ်မှာ Browser -> Backend -> Database ဖြစ်သည်။ frontend တွင် production database credential ရှိနေလျှင် developer tools မှတစ်ဆင့် data ကို တိုက်ရိုက် ဖတ်/ဖန်တီးနိုင်သည်။
- Relational (SQL) - table များနှင့် ဆက်စပ်မှု၊ structured data
- Document (NoSQL) - flexible, JSON-like record
- Key-value - key တစ်ခုတည်းဖြင့် လျင်မြန်သော lookup, caching
- Graph, time-series, search - အထူးပြုထားသော အမျိုးအစားများ
database type တစ်ခုမျှ universal အားဖြင့် အကောင်းဆုံး မဟုတ်ပါ - query syntax နှင့် administration ကို SQL, PostgreSQL, MongoDB သင်ခန်းစာများတွင် လေ့လာနိုင်သည်။
PROFILE PAGE LOAD SEQUENCE
--------------------------
PROFILE PAGE LOAD SEQUENCE
----------------------------
User opens profile page
|
v
Frontend requests profile data
|
v
Backend checks authentication ----> fails? reject, no query runs
|
v (authenticated)
Backend queries the database
|
v
Backend returns data to frontend
|
v
Frontend renders the profileလက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
User opens profile
user သည် profile page ကို ဖွင့်သည်။
Frontend requests
frontend သည် profile data အတွက် backend ဆီ request ပို့သည်။
Backend checks auth
backend သည် request တွင် valid authentication ပါဝင်မပါဝင်ကို စစ်သည်။
Backend queries DB
authenticate ဖြစ်မှသာ backend သည် database ကို query လုပ်သည်။
Backend returns data
backend သည် data ကို frontend ဆီ ပြန်ပို့သည်။
Frontend renders
frontend သည် data ကို profile page အဖြစ် render လုပ်သည်။
authentication ကို database မထိတွေ့မီ အရင်စစ်ရသည် - မဟုတ်လျှင် data ကို ခဏတာ မှားယွင်းစွာ ဖော်ပြနိုင်သည်။
အတူတူ စမ်းရေးကြည့်မယ်
const database = {
users: {
"user-1": { name: "Alice", email: "alice@example.com" },
"user-2": { name: "Bob", email: "bob@example.com" },
},
};
function getProfile(request) {
if (!request.authenticated) {
return { ok: false, error: "not authenticated - query never ran" };
}
const record = database.users[request.userId];
if (!record) {
return { ok: false, error: "user not found" };
}
return { ok: true, profile: record };
}
console.log("Authenticated request:", getProfile({ authenticated: true, userId: "user-1" }));
console.log("Unauthenticated request:", getProfile({ authenticated: false, userId: "user-1" }));authenticated request အတွက် Alice ၏ profile data ကို log ထုတ်ပြီး unauthenticated request အတွက် 'not authenticated - query never ran' error ကို log ထုတ်သည်။၅ မိနစ် စမ်းကြည့်
mock database ထဲသို့ user တတိယတစ်ဦး ထပ်ထည့်ပြီး မရှိသော userId အတွက် request တစ်ခု ရေးကာ valid session ရှိသော်လည်း record မရှိသည့် အခြေအနေကို function က မည်သို့ ကိုင်တွယ်သည်ကို ကြည့်ပါ။
သတိလေးတစ်ချက်
data access အားလုံးကို backend မှတစ်ဆင့်သာ လမ်းကြောင်းပို့မည့်အစား browser ကို database credential အထူးအခွင့်အရေးရှိသော direct ကို ကိုင်တွယ်ခွင့်ပေးခြင်း။
authentication မစစ်မီ database ကို query လုပ်ခြင်း - ၎င်းက ငြင်းပယ်ရမည့် request များကို data အနည်းငယ် ခဏတာ ဖော်ပြနိုင်သည်။
Wikipedia - Database — How the Web Works