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.ExecuteIds();
• 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.com/subject/
  1230559/

我对ORM的思考