Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Node.jsでシングルページWebアプリケーション

isoda yu
August 22, 2014

 Node.jsでシングルページWebアプリケーション

第2回 HTML5minutes! 〜triton-js〜 でのLTです。

isoda yu

August 22, 2014
Tweet

More Decks by isoda yu

Other Decks in Programming

Transcript

  1. .PEFMఆٛ TBJMTHFOFSBUFNPEFM.PEFM/BNF<BUUSUZQF BUUSUZQF ʜ> /** * UserModel */ module.exports =

    { attributes: { // Modelͷଐੑఆٛ name : { type: 'string' }, age : { type: 'integer' }, email : { type: 'email' }, gender : { type: 'enum' } } }; 9
  2. $POUSPMMFSఆٛ // $ sails generate controller <ControllerName> [action1, action2, …]

    /** * UserController */ module.exports = { /** * `UserController.index()` Userίϯτϩʔϥʔͷ index ΞΫγϣϯ */ index: function (req, res) { User.find({}).exec(function (err, users) { return res.json(users); }); }, /** * `UserController.add()` Userίϯτϩʔϥʔͷ add ΞΫγϣϯ */ add: function (req, res) { return res.view(); } }; 10
  3. /** * UserModel */ module.exports = { attributes: { //

    Modelͷଐੑఆٛ name : { type: 'string' }, age : { type: 'integer' }, email : { type: 'email' }, gender : { type: 'enum' } } }; σʔλݕূ 15
  4. σʔλݕূ /** * UserModel */ module.exports = { attributes: {

    name: { type: 'string', required: true, unique: true }, age: { type: 'integer', min: 20, }, email: { type: 'email', unique: true } // লུ 16
  5. σʔλετϨʔδͱಉظ 18 /** * UserController ͷ action಺ */ // ৽ن࡞੒

    User.create({ name: 'isoden', age: 20, email: '[email protected]', gender: 'male' }).exec(function callback(err, created) { // do something! }); ! // ݕࡧ User.find({}).exec(function callback(err, users) { // do something! });
  6. ϦΫΤετॲཧ಺༰ /user ɹɹɹɹ => ͢΂ͯͷModelΛฦ͢ /user/:id => IDʹϚονͨ͠ModelΛฦ͢ /user?prop1=val1 =>

    Model࡞੒ /user/update/:id?prop1=val1 => IDʹϚονͨ͠Modelͷଐੑߋ৽ /user/destroy/:id => IDʹϚονͨ͠ModelΛ࡟আ ! ! add to / create / destroy / find where / find one / populate where / remove from / update σʔλετϨʔδͱಉظ 19