applications without databases with dataMgr

I have often thought that many smaller applications could be more useful if they didn't use a database.  It isn't that I don't like databases, but all to often they become a barrier for adoption, testing, etc.   Those apps could easily run without a DB.  Easier to test and deploy in theory.    Plus writting applications to support multiple DB platforms can be a pain.

Wouldn't it be nice if those small applications that are read only for the most part didn't use a database at all?  On the other hand, writing those apps using only xml (or another format) can be a bit more of a pain than it is worth.  Using a database makes it so much easier really.  None of it is rocket science, but hey we use ColdFusion because it is easy right?  Why make our lives more complicated when we don't need to.

That is why DataMgr caught my eye last month.  It looked like the perfect tool for quickly and easily using an xml doc as a datasource.  I set out to make a quick sample web site as proof of concept and indeed it was quite easy.  So I figured I would post a bit about how it can be used. Note: Steve just posted his own entry on this topic as well.

DataMgr has a feature that lets one use a simulated database.  Very handy for testing, etc.  Not much has been written about using that as the primary db however.  

To do so you first need an xml document. First you specify the table structure.  I have just one table for this:

  <table name="PageData">
    <field ColumnName="RecordID" CF_DataType="CF_SQL_INTEGER" PrimaryKey="true" Increment="true" />
    <field ColumnName="MyTitle" CF_DataType="CF_SQL_VARCHAR" Length="80" />
    <field ColumnName="ShortDescription" CF_DataType="CF_SQL_VARCHAR" Length="80" />
    <field ColumnName="FullText" CF_DataType="CF_SQL_LONGVARCHAR" />
     <field ColumnName="FullURL" CF_DataType="CF_SQL_LONGVARCHAR" />    
  </table>



Then the data.  Here is one row for an example.

    <row
    MyTitle="My DataMGR Sim Sample from XML."
    ShortDescription="Home Page"
    FullText="#htmleditformat("<p>This is my full text.</p> <p>This is only for testing.</p>")#"
    FullURL = "#htmleditformat("http://bryantwebconsulting.com/cfcs/DataMgr2.htm")#"
    />

 Name this file mydata.cfm

Now we load that table and data into memory using the Application.cfm in my example.


<cfapplication name="dataMGRSimSample">

<cfif NOT isDefined('application.datamgr')>
    <cflock type="exclusive" scope="Application" timeout="10">
        <cfset Application.DataMgr = CreateObject("component","DataMgr").init("junkdb","Sim")>
    </cflock>
    
    <!--- This loads the data for the site.  Only do this when needed. --->
    <cfinclude template="mydata.cfm">
    
    <cfset Application.DataMgr.loadXML(mydata, true, true)>
    <!--- END  --->
</cfif>



Thats it!  We have now got all the data we need to query in any way we want.

For my home page I may do this:

<cfset myfilter = structNew()>
<cfset myfilter.RecordID = '1'>
<cfset mytabledata = application.DataMgr.getRecords('PageData', myfilter)>


 
I have just queried the sim db and gotten the record with recordID 1 from the PageData TBL.

Alternatively if I ran :

<cfset mytabledata = application.DataMgr.getRecords('PageData')>

I would get all records from that table.

I then output just like a query.

<cfoutput query="mytabledata">#mytitle#</cfoutput>


I have made a quick little example with a few pages. It isn't sexy by any means, but it shows how to make the data, load it and display it.  Just copy into a folder of your site and run. Download the zip here. What this code doesn't do is update the data in memory or update the XML doc.  Not hard to do, but will have to wait for another entry.  For a more detailed example site, check out my affiliate web site.  It is very self serving (I get money if people sign up) and was made just to test out this idea.  It uses multiple queries, filters, etc.  It took some time only because I had to research each program and write up little 'reviews' the code itself was cake.

I am not sold yet that it is completely safe or best practice  At one point is the benefit lost?   Plus there are a few things one would NOT want to do such as storing user/passwords in xml for example.   Seems to me it is worth pursuing.

TweetBacks
Comments

NAVIGATION

Home
About Me

RSS


Search

Subscribe

Enter your email address to subscribe to this blog.

Recent Entries

New Blog Design
Pre-Conference Training at cf.Objective()
FireFox 3.6 KTML Editor Fix
I am now a part of the Adobe Community Professionals Group
RIAdventure Was a Blas with photos

Recent Comments

submiting a form inside an iframe from outside the iframe
Peter said: I doubt you’re still having this problem over 2 years later, but if anyone else finds this page on t... [More]

FireFox 3.6 KTML Editor Fix
Dario Vargas said: Gracias por publicar la solución a la compatibilidad del KTML a Firefox 3.6 y la solucion al panel d... [More]

Vista Zip Slow and Broken?
betniurbo said: lzCfXK <a href="http://sapiensyckas.com/&...;, [url=http://zynqf... [More]

FireFox 3.6 KTML Editor Fix
Richard said: These fixes have worked on some issues, but any idea why the paragraph button no longer wants to wor... [More]

FireFox 3.6 KTML Editor Fix
joshua said: if I remember right, just change (this.edit.readyState != "complete") to (1 == 0) It is ... [More]

Calendar

Sun Mon Tue Wed Thu Fri Sat
 123456
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28       

Archives By Subject

blogs (31) [RSS]
books (4) [RSS]
Crazy (39) [RSS]
DIY (8) [RSS]
Flex (3) [RSS]
games (10) [RSS]
GRRR (13) [RSS]
Ideas (11) [RSS]
Local (14) [RSS]
LOLpics (2) [RSS]
money (9) [RSS]
music (3) [RSS]
Personal (27) [RSS]
Photos (8) [RSS]
Politics (8) [RSS]
Projects (22) [RSS]
Review (18) [RSS]
RPM (9) [RSS]
Spam (16) [RSS]
Technology (66) [RSS]
Testing (3) [RSS]
TV (15) [RSS]
video (32) [RSS]
Web Dev (217) [RSS]
World of Warcraft (16) [RSS]