ファイルDB_NeDB_のススメ.pdf

0aa238a274c2397214b20d6eed58939b?s=47 moomoo-ya
July 02, 2015
15

 ファイルDB_NeDB_のススメ.pdf

0aa238a274c2397214b20d6eed58939b?s=128

moomoo-ya

July 02, 2015
Tweet

Transcript

  1. ϑΝΠϧDB"NeDB" ͷεεϝ 2015.6.26 Isamu Suzuki Rakus co, ltd.

  2. ླ໦ ༐ • גࣜձࣾϥΫε • ੥ٻॻൃߦαʔϏεΛ։ൃͯ͠·͢ • ࢓ࣄͰ͸JavaʴJavaScriptগ͠ • ϓϥΠϕʔτ͸JavaScriptʹશྗ౤ࢿத

    • ࠷ۙPythonʹුؾͦ͠͏
  3. ࠓ೔ͷ͓୊

  4. Έͳ͞Μ

  5. ͪΐͬͱͨ͠πʔϧΛ ࡞Δͱ͖Ͱ΋ DB࢖͍͍ͨͳ͊ ͱɺࢥ͏͜ͱ͋Γ·͢ΑͶʁ

  6. Ͱ΋ ηοτΞοϓ͕

  7. (‘A`)ŵƃŪƄŞŤ

  8. ͬͯͳΓ·ͤΜ͔ʁ

  9. ͦΜͳ͋ͳͨʹ NeDB

  10. ஌ͬͯΔਓ͸ ஌Βͳ͍;Γਪ঑ ! ΋͘͠͸ϐβͲ͏ͧ

  11. Πϯετʔϧ npm install nedb --save ͍ͭ΋ͷҰߦʂ

  12. ॳظԽ var NeDB = require(‘nedb'); var db = new NeDB({

    filename: 'path/to/datafile' });
  13. ॳظԽʢෳ਺ϑΝΠϧͷ৔߹ʣ var NeDB = require(‘nedb’); var db = {}; var

    db.users = new NeDB({ filename: 'path/to/userfile' }); var db.items = new NeDB({ filename: 'path/to/itemfile' });
  14. ࢖͍ํ(insert) db.users.insert({name: ‘hoge'}); ! //ෳ਺Ϩίʔυͷૠೖ db.users.insert([ {name: 'foo'}, {name: 'bar'}

    ]);
  15. ࢖͍ํ(insert) db.users.insert([ {name: 'foo'}, {name: 'bar'} ], function(err, newDoc){ //΄͛΄͛;ʔ͹ʔ

    });
  16. ࢖͍ํ(find) db.users.find({ name: 'fuga' }, function (err, docs) { //

    ΄͛;͕;ʔ͹ʔ }); db.users.find({ name: /f*uga/ },//ਖ਼نදݱ function (err, docs) { // ΄͛;͕;ʔ͹ʔ });
  17. ࢖͍ํ(find & sort, skip, limit) db.users.find({ name: 'fuga' }) .sort({name:

    -1}), //name߱ॱ .skip(1) //1݅໨Λඈ͹ͯ͠ .limit(5) //5݅औಘ .exec(function (err, docs) { // ΄͛;͕;ʔ͹ʔ });
  18. ͓͍ɺͪΐͬͱ଴ͯ

  19. ͭ·Γ͜͏͍͏͜ͱ͔ʁ ʰզʑ͸mongodbͱಉ͡ ߏจͰ࣮૷Ͱ͖Δ……ʱ

  20. Exactly ʢͦͷͱ͓ΓͰ͍͟͝·͢ʣ ࡾ෦ऴΘΓ·ͨ͠Ͷ

  21. ࢖͍ํ(update) db.users.update({ name: 'fuga' }, { name: 'fungaar' }, {

    multi: true }, //ෳ਺ߦߋ৽ function (err, numReplaced) { // ΄͛;͕;ʔ͹ʔ });
  22. ࢖͍ํ(remove) db.users.remove({ name: 'fuga' }, { name: 'fungaar' }, {

    multi: true }, //ෳ਺ߦ࡟আ function (err, numRemoved) { // ΄͛;͕;ʔ͹ʔ });
  23. NeDBͷAPI͸ MongoDBͷαϒηοτ

  24. ͭ·Γ

  25. NeDBͰ࣮૷͓͚ͯ͠͹ MongoDBʹ ͙͢ҠߦͰ͖Δ

  26. ΋ͪΖΜ express-sessionͷ ηογϣϯετΞʹ΋ connect-nedb-session-two ͱ͍͏Ϟδϡʔϧ͕͋Γ·͢

  27. ݁࿦

  28. NeDB࢖ͬͯ ্खʹखΛൈ͍ͯ ॻ͖͍ͨ͜ͱ͔Βॻ͜͏ʂ

  29. ࠷ޙʹ એ఻͍ͤͯͩ͘͞͞

  30. גࣜձࣾϥΫε͸ ΤϯδχΞΛืू͍ͯ͠·͢ ʮླ໦ͷൃදΛݟͨʯ ͱ͓໰͍߹Θ͍ͤͩ͘͞