dbix datamodel
play

DBIx::DataModel Classes and UML-style associations on top of DBI - PowerPoint PPT Presentation

DBIx::DataModel Classes and UML-style associations on top of DBI (just an appetizer...) laurent.dami@justice.ge.ch LD, PJ-GE, july 2006 2 Agenda Introduction ORMs Design issues Unified Modelling Language (UML) Tables


  1. DBIx::DataModel Classes and UML-style associations on top of DBI (just an appetizer...) laurent.dami@justice.ge.ch

  2. LD, PJ-GE, july 2006 2 Agenda � Introduction � ORMs � Design issues � Unified Modelling Language (UML) � Tables � Declaration � Usage � Associations � Declaration � Usage

  3. Introduction � ORMs � Design issues

  4. LD, PJ-GE, july 2006 4 ORM : Object-Relational Mapping DBMS RAM r1 : class1 +c1 table1 +c2 c1 c2 c3 table2 +c3 c3 c4 r1 r2 r2 : class1 ... ...

  5. LD, PJ-GE, july 2006 5 What for ? [catalyst list] On Thu, 2006-06-08, Steve wrote: � Not intending to start any sort of rancorous discussion, � but I was wondering whether someone could illuminate � me a little? � I'm comfortable with SQL, and with DBI. I write basic � SQL that runs just fine on all databases, or more � complex SQL when I want to target a single database � (ususally postgresql). � What value does an ORM add for a user like me?

  6. LD, PJ-GE, july 2006 6 ORM useful for ... � navigation between tables � data conversions � generate complex SQL queries from Perl datastructures � expansion of tree data structures coded in the relational model � transaction encapsulation � data validation � auto-filling some columns at update � See Also : http://lists.rawmode.org/pipermail/catalyst/2006-June

  7. LD, PJ-GE, july 2006 7 ORMs in CPAN : TIMTOWTDI ! ... DBIx::SQLEngine ... DBIx::RecordSet Class::DBI Tangram Data::ObjectDriver Rose::DB::Object DBIx::Class ... Alzabo ORM ... Class::PObject SPOPS DBIx::DataModel

  8. LD, PJ-GE, july 2006 8 Some design issues � DRY : Don't Repeat Yourself � When to fetch column values, and which � Pure objects versus Perl datastructures � Encapsulation / collaboration with lower- level layers � Fine SQL tuning � Caching

  9. Unified Modeling Language

  10. LD, PJ-GE, july 2006 10 UML conceptual Model : example parent � � Author Package child � � ► contains � � Distribution Module � � ► depends on

  11. LD, PJ-GE, july 2006 11 UML terminology role name class ������ � � Author Package ����� association � association name multiplicity � ► contains � � Distribution Module � � ► depends on

  12. LD, PJ-GE, july 2006 12 Model implementation Author author_id author_name e_mail � link table for n-to-n association � Distribution Module � � distrib_id module_id distrib_name module_name d_release Dependency � � � � distrib_id module_id

  13. Tables [ and Views ] � declaration � usage

  14. LD, PJ-GE, july 2006 14 Schema and table declarations ��������������������������������������������� ������������������������������ �������������������������� ���������������!���������"�������#�����$"%�$ �����&�����'()*���������"��������������"�� *+� �����&�����'()*���������"���������������"��*+� �����&�����'()*���������"��������������"�� *+�

  15. LD, PJ-GE, july 2006 15 Don't Repeat Yourself generate Data Definition Statements Prog. DBMS Lang. get metadata from DBMS schema

  16. LD, PJ-GE, july 2006 16 Design philosophy Perl idioms : dual nature of DBMS tools for declaring Perl objects, dynamic schema, datatypes, typing, multiple inheritance, integrity rules, etc. etc. Prog. DBMS Lang. � freedom keep intersection � responsability to a strict minimum

  17. LD, PJ-GE, july 2006 17 Fetching data : example 1 ��,�����,����-�����$�%�$ ���$���,����.�������/�����������������0��� �$�1�������2���������,������������ ���������������������3������������,��#��444 )�������$��1%.�1/��2������51��������6 -�����71%���1/8�7 9 ��444����������:�������������������� ��������������;� � ���������������,,��$���,���� -�����1���������"������

  18. LD, PJ-GE, july 2006 18 Fetching data : example 2 ��������������-����������� �$�1������"���������2����������������� �������� 2��'()*�������"������"�������*+������. �)���� 2��6�"������� 2��6����2��1����"����99. �������$ 2����"���������<�!�������������������.� � ,��������$�1���������=1������"����������64449

  19. LD, PJ-GE, july 2006 19 Select API &����>�?��)��������� ��������� 2��8=�������.� ��>@�������������2��8=�������.� �)����� 2��85)����.� �3���-�$ 2��8=3���-��3�.� ���/��3 2��85��������.� �������$ 2��8=�����.� �,��� 2�����������$�.� �-��<���� 2��8A-��<���"�������%.� �-���<��� 2��8A-��<���"�������%.� ��������� 2�����)���BB�������BB���(�� BB������������ � � See Also : SQL::Abstract

  20. LD, PJ-GE, july 2006 20 Retrieving columns � programmer decides which ��������� 2��8=����������� ������$��,� ��������� 2��7���;.����C7� �������3 ��������� 2��707��������� ����,����� � no delayed fetching � objects have variable size ! � runtime error if missing keys � for following joins � for updates and deletes

  21. Associations � declaration � usage

  22. LD, PJ-GE, july 2006 22 Association declarations � � � � Author Distrib Module ������ �������� ������� ������� �����!�����������"�����������-�4�:���"%�$��� ����������������� '()*���������������������;�����������"��*+. '()*���������������������0�����������"��*+� ����������������� '()*���������������������;������������"��*+. '()*���������������������0������������"��*+�

  23. LD, PJ-GE, july 2006 23 Associations creates method which returns Distrib::author a single object ����������������� '()*���������������������;�����������"��*+. '()*���������������������0�����������"��*+� creates method which returns Author::distribs an arrayref creates method will generate Author::insert_into_distribs LEFT OUTER JOINS

  24. LD, PJ-GE, july 2006 24 Role methods ,��������$�1���������=1������"����������6 role �$�1�������2�1���������6�������"��9 methods �$�1�������2�1����������������� �$�1�����"���������2�1����������������� �)���� 2��6�������"�� 2��6�D���2��1��99. ��������� 2������������� � 9 same API as TableOrView::select()

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend