Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Aniki has come

2,913 views

Published on

The ORM as our great brother.
Gotanda.pm #7 vs Yokohama.pm #13

Published in: Software
  • Be the first to comment

  • Be the first to like this

Aniki has come

  1. 1. Aniki has come id:karupanerura Gotanda.pm #7 vs Yokohama.pm #13
  2. 2. What is Aniki? • Simple Architecture • Object Mapping • Relationship Support • Pluggable / Extendable • Fast
  3. 3. Concept of architecture:
  4. 4. “Do it simple stupid!”
  5. 5. Do it simple • Aniki - provides main interface • Aniki::Handler - provides DBI handling • Aniki::Schema - provides Schema meta API • Aniki::Result - provides SELECT query’s result • Aniki::Row - provides access to row
  6. 6. Don’t do difficult somethings • Delegate to: • DBIx::Handler (DBIx::TransactionManager) • DBIx::Schema::DSL (SQL::Translator) • SQL::Maker (SQL::QueryMaker) • SQL::NamedPlaceholder
  7. 7. Code Lines • Teng: 1908[lines] • Aniki: 2444[lines] • DBIx::Class: 39710[lines]
  8. 8. Modules • Teng: 18[modules] • Aniki: 25[modules] • DBIx::Class: 154[modules]
  9. 9. Rule of least surprise • Write clearly a side effect • e.g.) insert => execute insert only • e.g.) insert_and_fetch_id • e.g.) insert_and_fetch_row • No write clearly, No do it.
  10. 10. “Don’t repeat your self”
  11. 11. Don’t repeat your self • Abstraction Layers • Aniki::Handler - connection handling • Aniki::Reuslt::Collection - collection • Aniki::Result::Row - row of result
  12. 12. Don’t repeat your self • Object Mapping • Relationship Support • Plugin Architecture • I’ll talk about these later
  13. 13. “YAGNI”
  14. 14. Implement it later! • Relationship Support • I’ll talk about it.
  15. 15. Object Mapping
  16. 16. Object Mapping • Map a row to a row object • Can change the class of object each tables • Map rows to a collection object • Also you can it too :) • And, you can disable it, If you want.
  17. 17. Example: # $rows is a Aniki::Result::Collection my $rows = $db->select(user => {}); $rows->first; ## first of row
  18. 18. Example: # $rows is a Array my $rows = $db->select(user => {}, { suppress_result_object => 1, }); $rows->[0]; ## first of row
  19. 19. Example: # $row is a Aniki::Result::Row my $row = $db->select(user => { id => 1, }, { limit => 1, })->first; $row->id; ## => 1
  20. 20. Example: # $row is a Hash my $row = $db->select(user => { id => 1, }, { limit => 1, suppress_row_objects => 1, })->first; $row->{id}; ## => 1
  21. 21. DEMO
  22. 22. Example: # $user is a Aniki::Result::Row $db->update($user => { name => 1, });
  23. 23. Example: # $user is a Aniki::Result::Row $db->delete($user);
  24. 24. DEMO
  25. 25. Relationship Support
  26. 26. Relationship Support • Fetch related rows from ORM • a.k.a.) prefetch • Useful for suppress query executions.
  27. 27. Example: $db->select(user => { id => [1..10], }, { prefetch => [qw/user_items/], });
  28. 28. Example: $db->select(user => { id => [1..10], }, { prefetch => { user_items => [qw/item/], }, });
  29. 29. DEMO
  30. 30. Plaggable / Extendable
  31. 31. Pluggable • Mo[ou]se::Role is useful for plugin system • You can write plugin as Mouse::Role for Aniki
  32. 32. Extendable • Aniki • Aniki::Handler • e.g.) Aniki::Handler::WeightedRoundRobin • Aniki::Result::Row • Aniki::Result::Collection
  33. 33. Fast
  34. 34. Benchmark • SELECT: • 19% faster than Teng • 148% faster than DBIx::Class
  35. 35. Benchmark • INSERT(and fetch row): • 18% faster than Teng • 40% faster than DBIx::Class • INSERT(and fetch id): • 21% faster than Teng
  36. 36. Benchmark • UPDATE(from row): • 34% slower than Teng • 49% faster than DBIx::Class • UPDATE(from where condition): • 5% faster than Teng
  37. 37. Benchmark • DELETE(from row): • 2% slower than Teng • 422% faster than DBIx::Class • DELETE(from where condition): • 5% faster than Teng
  38. 38. Conclusion
  39. 39. Conclusion • Aniki is Simple, Simple is best. • Pluggable • Extendable • and, Fast
  40. 40. Thank you for listening

×