ORM Tools : Where FarCry Meets DataMgr

In the ColdFusion world these days we've got a variety of database abstraction tools to work with.

At one end we've got Steve Bryant's DataMgr which is a "Data Access Layer (DAL)" and is amazingly compact at under 50KB of code. And even with that little amount of code, DataMgr still does something most of the ORM tools don't and that's create tables. That feature is really useful for creating install scripts and/or upgrade scripts and the CFeMmy winning Savvy Content Manager is installed and upgraded using those features. But although it is somewhat robust, with less than 50KB of code, it certainly lacks features that other database tools have (and deliberately so). You will find no actual object-mapping (DAO or ActiveRecord) in DataMgr because it's not desiged to be an ORM tool. So if you want to create those things, you have to build them from scratch.

At the other end of the spectrum is one of the few other CF tools that will create database tables: the FarCry Framework. FarCry is... NOT compact. The zip archive of FarCry 5 is 11MB COMPRESSED and about 30MB once you've extracted it. But aside from the Godzilla-size footprint, FarCry also takes a very different approach to database management than the other tools. Where the most popular database tools for ColdFusion assume that you will create a database schema first and then use the tool to map objects to that schema, FarCry insists that you focus only on the objects and let it build the schema in FarCry's own way. According to FarCry if you're thinking about the database, then you're doing something wrong. Don't like UUID's? Too bad, 'cause the primary key on your table is going to be a UUID column called "objectid" (irrespective of the name of the table).

Each of these systems has advantages and drawbacks. What FarCry lacks in portability it makes up for in features. What DataMgr lacks in features it makes up for in portability. Though ultimately I think both DataMgr and FarCry represent the extreme ends of the spectrum with DataMgr seeking to be "light weight" and FarCry seeking to be "full featured". In between you have a handful of other ORM tools that are between 1MB and 2MB in terms of the footprint of the code. The most popular of them are Mark Mandel's Transfer ORM and Doug Hughes Reactor ORM. Yet neither of those tools offer any methods of installing database tables like DataMgr or FarCry. They both asume that you will have a pre-built database schema and then ask you to write some XML to tell them which tables to use and how they're related.

Which means that right now, DataFaucet is the only ORM tool for ColdFusion that will go both ways. It will allow you to use an existing database schema, or it will build the schema for you, it's your choice. It provides the object abstractions that DataMgr lacks while at the same time providing the flexible table-creation abilities that Transfer and Reactor lack, without the overhead (or restrictions) of FarCry. Yesterday I spent most of my day actually working on providing a bit more abstraction in DataFaucet, moving from using XML to define tables for installation to allowing you to use CFPROPERTY tags in much the same way they're used in FarCry.

Here's a sample from the DataFaucet documentation:

<cfcomponent output="false" extends="datafaucet.system.activerecord">
<cfproperty name="productid" type="uuid" required="true" key="1" />
<cfproperty name="productname" type="string" required="true" length="100*" />
<cfproperty name="productdescription" type="string" required="false" length="long*" />
<cfproperty name="productprice" type="numeric" required="true" length="real" />
<!--- create a foreign key constraint to ensure this product is placed in a category --->
<cfproperty name="categoryid" type="uuid" required="true" references="tblProductCategory.CategoryID" />

<cfset setTable("tblProduct") />

Compare this to a sample from FarCry:

<cfcomponent name="superhero" extends="farcry.core.packages.types.types" output="false" displayname="Super Hero">

<cfproperty name="title" type="string" default="" hint="Super hero title." />
<cfproperty name="teaser" type="string" default="" hint="Mini intro for super hero biography." />
<cfproperty name="biography" type="longchar" default="" hint="Super hero biography." />
<cfproperty name="secretIdentity" type="string" default="" hint="Super hero secret identity." />
<cfproperty name="lAlias" type="string" default="" hint="Comma separated list of alternative titles for the super hero." />
<cfproperty name="sidekick" type="uuid" default="" hint="Super hero sidekick." />
<cfproperty name="catHero" type="string" default="" hint="Category of hero." />
<cfproperty name="apowers" type="array" default="" hint="Array of superhuman powers." />


Unlike the FarCry example where CFPROPERTY tags are the only access to database schema, the same tags in the DataFaucet example are only syntax sugar built on top of existing XML-based table definitions. If the sugary abstraction isn't enough, if you need or want views or stored procedures, you can easily move from CFPROPERTY to creating the XML yourself. Also unlike FarCry you don't have to "deploy" this object from a "webtop" to install the tables -- all you have to do is instantiate one and the database tables will be created automatically.

The catch? You have to create the form yourself. :)

John Whish's Gravatar @Ike - very nice! I've used DataMgr but not FarCry and like being able to add tables and columns automagically (great for upgrades).
In your example you've got key="1". I'm guessing this indicates a primary key, also I take it that DataFaucet always use db generated primary keys.
# Posted By John Whish | 10/15/08 4:30 AM
Steve Bryant's Gravatar Just to clarify, DataMgr will let you use an existing database schema (without telling DataMgr the structure of your database) or it will let you define the schema and have DataMgr ensure that it exists as defined.
# Posted By Steve Bryant | 10/15/08 10:46 AM
ike's Gravatar @john - you're right about the key="1" being the designation for the primary key -- you can also specify the primary key if you want multiple columns as a <constraint> tag in the table definition if you're using the XML - but not using the cfproperty tags. As for using the primary key - the active record object has a setting to tell it which column is "primary" and then will automatically select that column if the table has a primary key constraint. So I generally don't tell it what column to use, but if for some odd reason you didn't want a primary key constraint (and I can't think of a good reason right now), then you could specify any given column as the primary column for that record.

@Steve - thanks for the clarification -- you're right, I omitted that mention in the article although I really should have pointed that out. Didn't mean to make it sound like that was a limitation or anything. :)
# Posted By ike | 10/15/08 3:34 PM
Steve Bryant's Gravatar No worries. I only mentioned it because you said that DataFaucet is the only ORM tool that goes both ways. That may be true - since DataMgr isn't an ORM. :-)
# Posted By Steve Bryant | 10/15/08 4:46 PM
ike's Gravatar @Steve -- yeah, actually that's where I'd intended originally to insert that clarification, that it is only because DataMgr isn't ORM. I just neglected to actually put that in there. :) So I implied that, but y'know, subtle implications are easy to overlook. :)
# Posted By ike | 10/15/08 6:51 PM
Geoff Bowers's Gravatar Hey, who you calling Godzilla! FarCry carries with it several third-party libraries, icon sets, sample applications and so on. The ORM componentry in isolation is just a few k ;)
# Posted By Geoff Bowers | 10/29/08 6:05 PM
rob's Gravatar I was going to say the same thing as Geoff - FarCry does quite a bit more than just function as an ORM system so using the file size as a hit is somewhat disingenuous. I would be like comparing a skeleton of a human with The Smashing Pumpkins. Yeah, they both have bones, but...

(None the less, it was an interesting post)
# Posted By rob | 10/29/08 6:19 PM
ike's Gravatar @Geoff + Rob -- That's true. :)

It wasn't really my intent to describe the file size as "a hit" any more than for DataMgr. It is what it is. Different people will want different tools and file-size will factor into that for some people and not for others. The crux being that, while it's true that the ORM in FarCry isn't very large by itself, it's not useful by itself (just as the skeleton of a member of the Smashing Pumpkins can't play guitar).

To borrow the rock band analogy, I would say that DataMgr is a human skeleton, DataFaucet is a musician (it plays guitar) and FarCry is an entire band... one that's inseparable. Plus roadies... :P Which is what I was getting at when I pointed out that "what FarCry lacks in portability it makes up for in features".

Some folks are looking for a whole band. But then some folks when looking for a drummer aren't going to be interested in a drummer who insists on bringing the base, keyboards and lead guitar along with him.

Yes absolutely, FarCry includes a lot of things that DataFaucet doesn't include. It really wasn't my intention to imply that FarCry and DataFaucet were equivalent in terms of functionality. But up until this latest release of DF there were features in FarCry that were inaccessible to anyone who was just looking for an ORM layer and didn't necessarily want all the other things that are in FarCry. There's a similar sort of relationship even between DF and DataMgr here too, where I'm sure many people would be much happier with the even smaller set of tools Steve Bryant provided if they're not really looking for a full-fledged ORM.

For example, Steve wrote an article here about porting Galleon to use DataMgr (with results that were pretty similar to mine): ://www.bryantwebconsulting.com/blog/index.cfm/2008/7/30/Galleon-on-DataMgr

I won't begrudge either set of users. People looking for the whole band, by all means, check out FarCry. People looking for something "light weight", check out DataMgr. But if you're just looking for an ORM that's portable between frameworks, this gives you those features that weren't previously portable. Heck, there's even a Fusebox lexicon in the archive. :)

Sorry for rambling... I know, I'm not very good at getting to the point. :)
# Posted By ike | 10/29/08 8:27 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.5.006. | Protected by Akismet | Blog with WordPress