Thursday, September 10, 2009

OpenBD Google App Engine and cfc's - Paul Kukiel



In my previous OpenBD on Google App Engine post I mention there is no relational database ( yet ) for OpenBD on GAE. There is however the ability to write and save objects directly to Googles Data Store. This sort of feels like working with an ORM but it's even more abstracted as there is not actual database that we can see but we can put objects in this place and run simple queries against the data sets.



Here is a code snippet:



Persisting Data:

  1.   
  2.   
  3. cfset v = createObject("component","Visitor").init() />  
  4.   
  5.   
  6.   
  7. cfset v.setFirstName("Paul"/>  
  8.   
  9.  
  10.       in a collection called Visitors --->   
  11.   
  12. cfset googleWrite(v,"Visitors"/>  
  13.   
  14.   
  15.   
  16.  
  17.       This will return an array of Obhjects ( cfc's ) that are 
  18.       in the datastore in the Visitor collection    --->  
  19.   
  20. cfquery name="dataStoreQuery">  
  21.   
  22. select  
  23.   
  24. from Visitors  
  25.   
  26. cfquery>  











select
from Visitors





Notice I must use variable.VariableName rather then cfproperty name="variableName this is explained here.



Here is a small application to demonstrate this in action:



Click Here for a live demo.
( Yes it looks like UniCode just works :) )



Being that it lives on Googles servers the application should be very fast and I expect Googles connections to be very fast you'll notice I do a cfhttp call in every page request you almost don't even notice it's happening.



I really have no metrics to judge/comment on the performance of the datastore but I am working on a project with Rob Parkhill which will make use of the datastore or the SQL engine that's being built so I may have something to report in a few weeks/months.



Here is the official OpenBD wiki entries on the datastore.



Here is the sample app code:






Visitor.cfc





Great intro by Paul to some very slick stuff with OpenBD on GAE! Make sure and read the comments--Vince is working on making this syntax compatible with the ORM functionality in CF 9.

No comments: