Your SlideShare is downloading. ×
0
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Sails.js Model / ORM introduce
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Sails.js Model / ORM introduce

10,477

Published on

Sails.js Model / ORM introduce

Sails.js Model / ORM introduce

Published in: Technology, Business
1 Comment
16 Likes
Statistics
Notes
  • How about many-to-many dude? I'm still confused about that.. could yo give me a sample console to exec create record in database about this association. I've already tried this but failed:
    Post.create({title: 'example title',owners:[{1,2}]}).exec(console.log)

    I defined in Post an Category model like this:
    Category Model:
    posts: {
    collection: 'post',
    via: 'owners'
    }

    Post Model :
    owners: {
    collection: 'category',
    via: 'posts',
    dominant: true
    }

    Help me, please! Thanks.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
10,477
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
101
Comments
1
Likes
16
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Sails.js Model / ORM introduce
  • 2. http://sailsjs.org/
  • 3. 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
  • 5. • config/connections.js • addconfig/models.js DB Setting
  • 6. Why you need ORM ?
  • 7. How Create Table? traditional way
  • 8. 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
  • 9. MySQL
  • 10. SELECT * FROM `post` WHERE `id` = '1' LIMIT 1; MySQL
  • 11. MySQL
  • 12. Terrible happened • DB schema modify • Multi tables join • Migrate Table or Database • Change adapter • more ...
  • 13. Can we controller Model from Code???
  • 14. ORM Objective Orient Model
  • 15. Object Orented
  • 16. adpters
  • 17. one of best practices
  • 18. Sql & Nosql
  • 19. SQL vs. MongoDB
  • 20. Waterline Sails.js ORM module
  • 21. Model • file path -> api/models • Capital naming • Set schema and rule. • ORM like • you can use multi-adapter
  • 22. Model Associations • sails 0.10 new Feature • Many-to-Many • One-to-Many • One-to-One
  • 23. Disk database (default)
  • 24. Adapter support • MySQL • MongoDB • Redis • ... • http://sailsjs.org/#!documentation/models
  • 25. Adapter config
  • 26. • config/connections.js • addconfig/models.js DB Setting
  • 27. Attribute type • string • text • integer • float • date • time • datetime • boolean • binary • array • json
  • 28. Custom Defined Instance Methods
  • 29. example, api/models/Post.js
  • 30. example, api/models/Post.js generate a table and column
  • 31. Auto migration
  • 32. example2, api/models/Post.js insert a attribute in Post model
  • 33. Before and After
  • 34. Lifecycle Callbacks sails model
  • 35. define Model Associations
  • 36. One to One
  • 37. One to Many
  • 38. Controller and Model
  • 39. example, controller call Post model
  • 40. example, controller call Post model model name
  • 41. example, controller call Post model model behavior
  • 42. example, controller call Post model new data
  • 43. example, controller call Post model success callback & response
  • 44. Model document http://sailsjs.org/#!documentation/models
  • 45. • 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);

×