Extending DataMgr 2.5
One of the new features in the upcoming DataMgr 2.5 release that I am really excited about is the ability to extend DataMgr to add or modify its functionality to your liking. This is a feature that John Farrar really had to push me into. Now that I finally see the light, however, I am really excited about the possibilities.
One possibility (also from John) is to return records as arrays of structures instead of queries (for AJAX and the like). I will likely add that into a future build for release in 2.5, but in the meantime it can be added as an extended feature in any copy of the current build.
To do this, I started by opening up DataMgr.cfc. By default, it looks like this:
Since I know that I am going to want to convert a query into an array of structures, I next looked for a function to do that. I found Ben Nadel's QueryToArray which looked to handle my need nicely. I reformatted it very slightly and changed the "access" to "private" and dropped it into DataMgr.cfc.
After that, I just needed to write the actual "getCollections" function. I decided to have the argument tags in the function so that it could be called just like getRecords (either ordinally or by named arguments). The function calls getRecords and return the converted results.
<cfargument name="tablename" type="string" required="yes">
<cfargument name="data" type="struct" required="no">
<cfargument name="orderBy" type="string" default="">
<cfargument name="maxrows" type="numeric" required="no">
<cfargument name="fieldlist" type="string" default="">
<cfargument name="advsql" type="struct">
<cfargument name="filters" type="array">
That's it! Now my local copy of DataMgr has a getCollections method that does what I want. That functionality may end up being in the final release of DataMgr 2.5, but the real point is how easy it will be to extend DataMgr to fit your needs.
As of this writing, DataMgr 2.5 is in alpha but the full release is available from RIAForge.org
copy paste and hope you did it right when base libraries you modify are updated. It's easier to extend, and easier to
keep in sync! :)
The point of this is definitely more about the ability to extend DataMgr to your own liking rather than the specific example of returning an array of structures.
Although I may offer this method as a native option in DataMgr, returning queries is still the focus. For me, queries are one of the under-appreciated gems of ColdFusion.