DataFaucet ORM


Welcome to the wonderful world of ORM.

DataFaucet is a simple system for managing database access, making your ColdFusion applications:

By using this library I was able to eliminate about 600 lines of code from Ray Camden's Galleon Forums application and at the same time add features and flexibility.

NOTE: Documentation for DataFaucet assumes that you have a basic understanding of Adobe ColdFusion and CFCs.

What DataFaucet is NOT

DataFaucet is not

What is ORM?

Object Relational Modeling (ORM) simply put is a way of standardizing the manner in which you store data in a relational database and how the objects in your application talk to databases. Using an ORM eliminates many of the routine or "boring" aspects of application development so that you can focus on more important things like your business model / logic and user interaction.

Can you give me an example?

I certainly can. Turn this SQL-Server-specific code:

<cfparam name="form.productID" default="" />

<cfquery datasource="#MyDSN#" username="#dbUsr#" password="#dbPwd#">
<!--- check to see if this is a new product --->
<cfif len(trim(form.productID))>
  <!--- product already exists - perform an update --->
  UPDATE tblProduct SET 
  [NAME] = <cfqueryparam value="" cfsqltype="cf_sql_varchar" />,
  description = <cfqueryparam value="#form.description#" cfsqltype="cf_sql_varchar" />,
  price = <cfqueryparam value="#form.price#" cfsqltype="cf_sql_real" />
  WHERE productid = <cfqueryparam value="#form.productID#" cfsqltype="cf_sql_varchar" />
  <!--- product is new - give it an id and insert it --->
  <cfset form.productID = CreateUUID() />
  <cfqueryparam value="#form.productID#" cfsqltype="cf_sql_varchar" />,
  <cfqueryparam value="" cfsqltype="cf_sql_varchar" />,
  <cfqueryparam value="#form.description#" cfsqltype="cf_sql_varchar" />,
  <cfqueryparam value="#form.price#" cfsqltype="cf_sql_real" />

into this platform-independent code for ANY database:

<cfparam name="form.productID" default="" />

<!--- get the datasource --->
<cfset ds = request.DataFaucet.getDatasource() />

<!--- get a product record --->
<cfset Record = ds.getActiveRecord(className="ar.product").init(form.productid) />

<!--- save product data to the database --->
<cfset Record.update(form) />

For an example of what you can do with DataFaucet in an afternoon, see the Waterlog sample application.

For a more traditional ORM example, try the Maze Game (some assembly required).

Additional Resources

If you need help getting started or additional resources beyond this documentation, join our discussion group.