More Related Content Similar to Sails.js Model / ORM introduce (20) Sails.js Model / ORM introduce3. sails 0.10 beta
• sails-0.10.0-reference
• .done() vs. .exec()
• Model Associations
• sails console
• promises in core
4. sails upgrade 0.10 beta
• npm i sails@beta -g
• npm i sails@beta -save
• npm i sails-mysql@beta -save
• npm i sails-mongo@beta -save
9. SHOW CREATE TABLE `post`;
!
ALTER TABLE `post` ADD `title`VARCHAR(100) NULL DEFAULT NULL AFTER `id`;
!
ALTER TABLE `post` ADD `content` TEXT DEFAULT NULL AFTER `title`;
MySQL
13. Terrible happened
• DB schema modify
• Multi tables join
• Migrate Table or Database
• Change adapter
• more ...
22. Model
• file path -> api/models
• Capital naming
• Set schema and rule.
• ORM like
• you can use multi-adapter
47. • User.create({name:"smlsun"}).exec(console.log);
• Post.create({title:"post", content:"body", user:
1}).exec(console.log);
• Post.create({title:"post another", content:"body", user:
1}).exec(console.log);
• Post.find().exec(console.log);
• Post.find().populate("user").exec(console.log);
• User.find().populate("posts").exec(console.log);
• Profile.create({email: "smlsun@gmail.com", user:
1}).exec(console.log)
• Profile.find().populate("user").exec(console.log);