Object Relational Mapping

Posted by PunNeng, Thu Dec 01 00:41:00 UTC 2005

ผมจะเรียกมันว่า ORM นะครับ

ORM คือ การ Links ให้ Database แบบ Relation ไปเป็นแบบ object-oriented language จะมีลักษณะแบบ virtual object database คือเป็น Database แบบเสมือนขึ้นมา เพราะพอตอนที่เข้าไปเก็บข้อมูล มันก็จะเข้าไปเก็บใน Database ที่เป็น Relation เหมือนเดิม

The term object/relational mapping (ORM) refers to the technique of mapping a data representation from an object model to a relational data model with a SQL-based schema.

ที่มา

อันนี้เป็นความชอบส่วนตัวครับ เพราะผมไม่ชอบ SQL Command เป็นอย่างมาก ถ้าจะเข้าถึง Database นะ ดูนี่ ง่ายๆ โดย PHP

แต่ถ้าเป็น ชุดที่ทำการ mapping แล้วล่ะ โดย DataObject ของ PEAR

สั้นกว่าเห็นๆ ไม่ต้องมี SQL มายุ่งให้ปวดหัว

ลองมานั่งนึกดูนะ มันจะไม่ค่อยมีอะไรใหม่ๆ เข้ามาอย่างเห็นได้ชัด มากมายนักหรอก ไม่ว่าจะเป็น PHP หรือ programming language ต่างๆ แต่มันจะมีตัวช่วยแบบนี้แหละ โผล่มาเรื่อยๆ โดยตัวนี้เนี่ย จะเป็นตัวช่วยอย่างมาก สำหรับนักพัฒนาที่ไม่ชอบไปยุ่งกับ SQL อย่างเช่นผม แต่ก็อย่าทิ้ง SQL ไปเลยซะล่ะ ถึงแม้ว่ามันจะมีตัวช่วยที่ง่ายๆ แบบนี้ เข้ามาก็ตาม

ORM Tools

มาดูเครื่องไม้เครื่องมือในการทำ ORM ดีกว่า ว่าแต่ละ language จะมีอะไรคอยช่วยบ้าง

PHP

  • AYLOOP (http://homepage.mac.com/sbarnum/code/alyoop/)
  • Changes (http://www.sitepoint.com/forums/showthread.php?t=214183)
  • DB_DataContainer  (http://www.appelsiini.net/~tuupola/php/DBDataContainer/): DBDataContainer is a PEAR compliant database persistence layer and data encapsulation class. Based on ActiveRecord.
  • DB_DataObject (PEAR) - official PEAR page  (http://pear.php.net/package/DB_DataObject)
  • DBTable (http://wiki.ciaweb.net/yawiki/index.php?area=DBTable): DB_Table is an object-oriented interface to a database table. PEAR-compliant. Based on ActiveRecord.
  • DBDO (PECL) (http://pecl.php.net/package/DBDO): Same as DB_DataObject, except as a PHP Extension
  • Entity (http://tanus.dotgeek.org/): The Entity framework is a generic object to database mapping architecture.
  • EZPDO (http://www.ezpdo.net): Eazy PHP Data Objects, a lightweight and easy-to-use object-relational mapping and data persistence solution for PHP
  • LDO (http://www.wojciechszela.com): Lightweight Data Objects, lightweight, open, feature rich and intuitive persistence solution for PHP
  • Metastorage (http://www.meta-language.net/metastorage.html): Metastorage is an application that automatically generates code for an Object Oriented API to store, retrieve and manipulate the data objects of classes described in a high level data model definition.
  • MyObjects (http://www.myobjects.org/): MyObjects is a set of tools for class generation, database schema generation and object persistence for Php 5 and MySql.
  • phpersistence (http://www.phpersistence.org/): phpersistence is an object oriented persistence layer for php, using transparent object relational mapping.
  • PhpOpenbiz (http://www.phpopenbiz.org/) PhpOpenbiz is a metadata-driven framework that implements MVC, ORM and object persistence. It also has an Eclipse plugin to help ORM configuration.
  • PPO (PHP Persistent Object) - Changes for PHP5
  • Perdure (http://sourceforge.net/projects/perdure/): Perdure is a transparent object relational persistence and query tool for PHP.
  • Propel (http://propel.phpdb.org): Propel is a full-service object persistence and query toolkit for PHP5.
  • phpCr (http://www.phpcr.org/): php Content Repository is a collection of interfaces. It aims to provide a framework for implementing jsr-170 (http://jcp.org/aboutJava/communityprocess/pfd/jsr170/index.html) for php.
  • DBOO & DBOO2  (http://www.sergiocarvalho.com/wiki/OpenSourceSoftware/#toc3): A PEAR-compliant orm for php4 and php5
  • Php Object Generator (POG)  (http://www.phpobjectgenerator.com/): Free Online Generator which automatically generates tested ORM code that you can use for your PHP4/PHP5 application.
  • Qcodo (http://www.qcodo.com/): Code-generation based PHP Development Framework that not only creates your ORM, but also creates classes for your forms. Architected to allow full customization to work hand-in-hand with infinite code regenerations. Recently presented at the Zend/PHP Conference (http://zend.kbconferences.com/).
ผมจะใช้ DB_DataObject ของ PEAR เป็นตัวอย่างในการอธิบายตอนต่อไปนะครับ

Java

เยอะมากครับ เอา links ไปดูเองดีกว่า http://www.javaskyline.com/database.html ผมเคยใช้ Hibernate อันเดียวคับ แต่เท่าที่ลองใช้มา ผมว่ามันครบเครื่องแล้ว

.Net

เยอะพอกันกับ Java เลย links เหมือนกัน http://sharptoolbox.com/Category74089b0a-1105-4389-b1db-eedf27e20cfb.aspx ฝั่ง .Net นี่ มี nHibernate ด้วยครับ ไม่เคยใช้เหมือนกัน แต่ดูจากค่ายแล้ว มัน Hibernate เหมือนกัน คงจะดีเหมือนๆ กับ Hibernate ของ Java

มีเครื่องไม้เครื่องมือในการอำนวยความครบครัน ชีวิตในการเขียนโปรแกรมจะง่ายขึ้นอีกเป็นกอง คุณๆ ทั้งหลาย เตรียมรับมือกับของพวกนี้หรือยังครับ

แก้ไขล่าสุด วันที่ 19 มิถุนายน 2550 เวลา 3.10 น.

ปล. ต้องแลกกันครับ ระหว่างการที่เราทำงานง่ายขึ้น แต่โปรแกรมเราทำงานนานกว่าเดิม ซึ่งผมเลือกให้เราทำงานง่ายขึ้นครับ แต่ถ้าระบบใหญ่ๆ ก็ต้องมาพิจารณากันอีกทีนึง

Filed Under: General | Tags: database orm php

Comments

codegent: we're hiring