Brian Hoke Presents at ColdFusion User's Group of Central New York: Object-Relational Mapping in ColdFusion
Brian Hoke's talk at today's CFUGCNY meeting explained object-relational mapping, presented some code examples, and listed some tools for code generation. An overview of the discussion, along with links to source code, is below.
What is ORM?
- Code development strategy using OOP classes to "wrap" SQL tables
- Every DB table has a corresponding CFC
- Client code uses CFC ("person.getFname()") instead of CFQUERY
- Best of both worlds: maintainable, team-able code through OOP; storage of data in (familiar) SQL DB
- Ruby on Rails, symfony
- automating the process - tools to create classes from DBs
(Examples below assume a ColdFusion DSN named "CFUGCNY_ORM" points to a database with a table People)
Traditional Development
Data resides in SQL tables, logic resides in CF templates - things and operations on those things are not tied together; making changes (new DB schema, different SQL vendor, new operations on data, etc.) requires digging into each CF template
Code Example: people-sql.cfm.txt
ORM Development
Data resides in SQL tables but abstracted in layer of OOP classes (CFCs) - things and operations on those things are tied together; making changes easier, since "person" code (data storage, operations on those data) is collected in one spot and abstraction layer makes swapping SQL flavor/vendor/schema much easier
Code Example: people-orm.cfm.txt | person.cfc
Reactor
Reactor is an ORM tool that generates on-the-fly CFCs from existing DB tables
Code Example: people-reactor.cfm.txt
More Info
This item was published on 06/12/2007

