1
800

Sql And Nosql Database

Myo Thant Kyaw

Hello အားလုံးမင်္ဂလာပါ

ဒီနေ့ database အကြောင်းကိုနည်းနည်းဆွေးနွေးကြပါမယ်။


ဒီ article မှာ အဓိကပြောချင်တာက  sql နဲ့ nosql အကြောင်းပါ


Database ဆိုတာဘာလည်း

ဘာအတွက်သုံးရမှာလည်း

relational database  ဆိုတာဘာလည်း

non relationsal database ဆိုတာဘာလည်း

nosql vs sql ဘယ်ဟာပိုကောင်းလည်း (ဒါကတော့မပါပါဘူး :P)

စသဖြင့် ဒီခေါင်းစဉ်တွေပေါ်မူတည်ပီးဆွေးနွေးပေးမှာဖြစ်ပါတယ်။


Dynamic website တွေဖြစ်ဖြစ်

user တွေနဲ့ interactiveဖြစ်တဲ့ application တွေမှာဖြစ်ဖြစ်

အကြာင်းအမျိုးမျိုးကြောင့် database တွေကိုအသုံးပြုရပါတယ်။


database တွေမှာ အဓိကအားဖြင့်ရွေးချယ်စရာ ၂မျီုးရှိနေတယ်ပေါ့

relational (sql) နဲ့ nonrelational(nosql) databaseတွေပေါ့ 


relational database ကိုစပီးဆွေးနွေးကြည့်ရအောင်

website or app တစ်ခုရဲ့  article တစ်ခု ကို  detail ကြည့်နေတယ်ဆိုပါဆို့

article (table)
========
id title description author tags comments likes


article table ကနေ id တစ်ခုခုနဲ့တူတဲ့အချက်အလက်ကိုဆွဲထုတ်ပီး 

detail ပြရပါတော့မယ်

ဒီမှာ author ဆိုတာ က userinformation သိမ်းထားတဲ့အချက်အလက်ဖြစ်ပါတယ်

author table , tags table , comments table , likes table 

ဒီလိုtable တွေဆက်ဖန်တီးပေးဖို့လိုပါတယ်။

ဒီအပေါ်မှာမူတည်ပီး relationship တွေစသတ်မှတ်ရမှာဖြစ်ပါတယ်

ထိပ်က အချက်အလက်ရဆိုရင် 


article table ကို author တစ်ယောက်ကပဲရေးမှာမလို့

article record  တစ်ခုမှာ  author table က idကိုချိတ်လိုက်ခြင်းအားဖြင့်

articleတစ်ခုကိုဘယ်သူရေးတယ်ဆိုတာကိုသိနိုင်မှာဖြစ်ပါတယ်

ဒါကြောင့် article tableနဲ့ချိတ်ဆက်(join ) ပီးအချက်အလက်ကိုရယူနိုင်ပါတယ်


author တစ်ယောက်က article record တွေအများကြီးရေးနိုင်တာမလို့

one to many relationshiop ဖြစ်ပါတယ်။


tagsမှာဆိုရင်တော့ အနည်းငယ်ကွဲသွားပါပီ

article record တစ်ခုမှာ  tags  တွေအများကြီးရေးနိုင်သလို

tags တစ်ခုကနေကြည့်ရင်လည်း article record တွေအများကြီးဖြစ်နိုင်တာမလို့

many to many relationship ဖြစ်ပါတယ်။


ဒီလို  relationship တွေအများကြီးရှိနေပါသေးတယ်

(master php course မှာ database chapter ပါဝင်ပီး relational database(mysql) ကိုလည်းလက်တွေ example တွေနဲ့အသးစိတ်သင်ပေးထားပါတယ် ကြော်ညာ :P)


nosql ကိုဆက်သွားရအောင်ပါ။

nosql တွေက relational database တွေလို table တွေနဲ့မသိမ်းတော့ပါဘူး

bson type နဲ့သိမ်းပါတယ် (အများအားဖြင့်)


bson ဆိုတာ binary json ကိုပြောတာဖြစ်ပါတယ် 

json ထက်အဆင့်မြင့်တဲ့ sturcture တစ်ခုပေါ့

nosql တွေမှာ table တွေကို schema လိုသုံးပါတယ်

Article schema
{
"_id":"id",
"title":"What is php",
"author":{"name":"mtk"},
"tags":[
{"name":"web dev"},
{"name":"php"},
]
}

အပေါ်က shcema ကိုကြည့်ပါ

nodql မှာ relationship တွေအတွက်သိပ်စိတ်ပူစရာမလိုပါဘူး

author ကို article table(schema) ထဲမှာပဲတစ်ခါတည်း သိမ်းထားသလိူ

tag တွေကိုလည်း schemaထဲမှာပဲ array datatype နဲ့သိမ်းထားပါတယ်

relation database တွေလို join စရာမလိုပါဘူး


ဘယ်ဟာကပိုမြန်တယ်

ဘယ်ဟာကိုပိုကောင်းတယ်ဆိုတာကိုတော့ 

ကိုယ်တိုင်ပဲအသုံးချကြည့်ပီး

ရှာဖွေဖတ် ကြည့်ပါ


see you next article guyz  👊

Comment:
Please Login To Create Comment Login
Loading...
paingsoethu 2015 1 year ago ကောင်းတယ်ဆရာရေ။ NON SQL မှာ USER တစ်ယောက်မှာ pOST တွေအများကြီးရိုနိုင်ပါတယ်။ဥပမာ Schema က ------------------------------------------------------------------------------------ const userSchema = new Schema({ name:{ type:String, required:true, }, email:{ type:String, required:true, unique:true }, password:{ type:String, required:true, minLength:6, }, posts:[{ type:mongoose.Types.ObjectId, ref:"Post", required:true }], }, { timestamps: true } ) --------------------------------------------------------------------------------- const postSchema = new Schema({ title:{ type:String , required : true}, description:{type:String, required:true}, user:{ type:mongoose.Types.ObjectId, ref:"User", required:true, } }, {timestamps:true} ) -------------------------------------------------------------------- အဲဒီ Schema ၂ ခုရှိပြီး post sCHEMA အတွက် ပို့တစ်ခုတင်တိုင်း User id ပါရမှာဖြစ်ပါတယ်။ အဲဒီအတွက် cONTROLLER ADDPOST METHOD ကိုဒီလိုရေးလိုက်ပါတယ်။ export const addPost = async (req, res, next) => { try { const exitUser = await User.findById({_id:req.body.user}); if(!exitUser){ return res.status(404).json({ message:"Not User ID Found" }) } let user = { name:exitUser.name, email:exitUser.email, }; const post = new Post(req.body); const savePost = await post.save().then(post=>{ exitUser.posts.push(post); exitUser.save(); return res.status(200).json({ message:"New Post Successfully", post:{ _id:post._id, title:post.title, description:post.description, user:user }}) }); } catch (error) { next(error); } }; အဲဒီမှာ ပို့လာတဲ့အချက်အလက်တွေကို post sCHEMA မှာ save() ကိုသုံးပြီးနောက် post id ကို push ကိုသုံးပြီး သက်ဆိုင်ရာ User sCHEMA ထဲက POSTS Array ထဲ့ကိုသွားထည့်ပါတယ်။ ဒါဆိုရင် သက်ဆိုင်ရာ user မှာ သက်ဆိုင်ရာ POST ID တွေရောက်သွားပါပြီ။ ထို့နောက် USER ကိုခေါ်မယ်ဆိုရင် သက်ဆိုင်ရာရဲ့ ပို့စ်တွေကို ရပါပြီ။ #######သိချင်တဲ့အပိုင်းရောက်ပါပြီဆရာ######### post တစ်ခုကို ဖျက်လိုက်မယ်ဆိုရင် USER SCHEMA ထဲက posts arrary ထဲ့ကမှ သက်ဆိုင်ရာ POST ID ကို ရွေးဖျက်သွားချင်တာပါ။ အဲဒီအတွက် ဘယ်လိုသုံးရမလဲခင်ဗျ။ လေးစာလျှက်.......အားပေးနေမယ်...........ဆရာ။