ORM
Why ORM?
Why ORM?

•
Why ORM?

•
•   SQL
Why ORM?

•
•   SQL
Why ORM?

•
•   SQL



•
O - Object
O - Object


•
O - Object


•
• Admin inherits User ?
R - Relational
R - Relational

• CRUD
R - Relational

• CRUD
• 3NF
R - Relational

• CRUD
• 3NF
 •
M - Mapping
M - Mapping


• O => R ?
M - Mapping


• O => R ?
• R => O ?
R=>O


•
•
ActiveRecord

•
•
•
• ORM =
•
•
•
•
•
•
•
•

•
N + 1 VS 1
N + 1 VS 1

• select * from blogs
N + 1 VS 1

• select * from blogs
N + 1 VS 1

• select * from blogs
N + 1 VS 1

• select * from blogs


• select id from blogs
N + 1 VS 1

• select * from blogs


• select id from blogs
 • select * from blogs where id=X
• Objects
• Lists
• FetchById
• FetchById
 •
• FetchById
 •
 •
• FetchById
 •
 •
• FetchById
 •
 •

• FetchByIds
• select * from blogs where user_id = XXX
    order by id desc
•
• where column1 = XXX
 • and column2=YYY
• order by id desc
• count(*)
• Query q = Blogs.Query();
• q.AddWhere(“user_id”, XXX);
• q.OrderBy(“id”, “desc”);
• q.Start = 0;
• q.count = 10;
• q.Exe...
• Query q = Blogs.Query();
• ....
• q.CountIds();
•
•
•

•
•

•
    • Delete by old value
•

•
    • Delete by old value
    • Add by new value
•
•
•
• SubSonic http://subsonicproject.com/
• Cache Money http://github.com/nkallen/
  cache-money
• PEAA http://book.douban.co...
我对ORM的思考
我对ORM的思考
我对ORM的思考
Upcoming SlideShare
Loading in …5
×

我对ORM的思考

611 views

Published on

  • Be the first to comment

  • Be the first to like this

我对ORM的思考

  1. 1. ORM
  2. 2. Why ORM?
  3. 3. Why ORM? •
  4. 4. Why ORM? • • SQL
  5. 5. Why ORM? • • SQL
  6. 6. Why ORM? • • SQL •
  7. 7. O - Object
  8. 8. O - Object •
  9. 9. O - Object • • Admin inherits User ?
  10. 10. R - Relational
  11. 11. R - Relational • CRUD
  12. 12. R - Relational • CRUD • 3NF
  13. 13. R - Relational • CRUD • 3NF •
  14. 14. M - Mapping
  15. 15. M - Mapping • O => R ?
  16. 16. M - Mapping • O => R ? • R => O ?
  17. 17. R=>O • •
  18. 18. ActiveRecord • • •
  19. 19. • ORM = •
  20. 20.
  21. 21. • •
  22. 22. • •
  23. 23. • • •
  24. 24. N + 1 VS 1
  25. 25. N + 1 VS 1 • select * from blogs
  26. 26. N + 1 VS 1 • select * from blogs
  27. 27. N + 1 VS 1 • select * from blogs
  28. 28. N + 1 VS 1 • select * from blogs • select id from blogs
  29. 29. N + 1 VS 1 • select * from blogs • select id from blogs • select * from blogs where id=X
  30. 30. • Objects • Lists
  31. 31. • FetchById
  32. 32. • FetchById •
  33. 33. • FetchById • •
  34. 34. • FetchById • •
  35. 35. • FetchById • • • FetchByIds
  36. 36. • select * from blogs where user_id = XXX order by id desc •
  37. 37. • where column1 = XXX • and column2=YYY • order by id desc • count(*)
  38. 38. • Query q = Blogs.Query(); • q.AddWhere(“user_id”, XXX); • q.OrderBy(“id”, “desc”); • q.Start = 0; • q.count = 10; • q.ExecuteIds();
  39. 39. • Query q = Blogs.Query(); • .... • q.CountIds();
  40. 40.
  41. 41.
  42. 42. • •
  43. 43. • • • Delete by old value
  44. 44. • • • Delete by old value • Add by new value
  45. 45. • • •
  46. 46. • SubSonic http://subsonicproject.com/ • Cache Money http://github.com/nkallen/ cache-money • PEAA http://book.douban.com/subject/ 1230559/

×