Home | Blog | Twitter @AndyJ | Contact Me | Snippets/Downloads | RSS

Transfer and TQL

I love working with Transfer and Mark Mandel has done an amazing feat of giving it some really good documentation. But I remember when I was getting started I was looking for a rough guide to the TQL language for Transfer and how to implement it. So based on all the information at www.transfer-orm.com/transfer/documentation/ here's a quick start to TQL. Please note: I am presuming you already know how to set up Transfer and have basic knowledge of how it works. For this example here is our Transfer.xml configuration file:
   view plainprintabout
 <package name="post">
     <object name="Post" table="post_table">
         <id name="postid" column="postid" type="numeric"/>
         <property name="postText" type="string" column="postText" />
         <property name="postDate" type="date" column="postDate" />
     </object>
 </package>
First we need to create our (S)TQL statement. TQL is Transfers own scripting language written in Java and ColdFusion. The main difference over SQL is that you are referencing classes and properties from your Transfer.xml file (see above). So to run a "SELECT * FROM" the post_table our TQL would look like:
   view plainprintabout
 <cfsavecontent variable="tql">
 <cfoutput>
     SELECT * FROM post.Post
 </cfoutput>
 </cfsavecontent>
You can see here that in the query instead of using the table name after FROM we are using the Transfer Class post.Post. Next we use the TQL and create the query. Note at this point you are not running the statement against the database, you are just creating a TQL.query object.
   view plainprintabout
 <!--- getTransfer().createQuery() returns a transfer.com.tql.Query object --->
 <cfset tqlObj = getTransfer().createQuery(TQL);
Once we have the object returned we just need to pass it on to one of Transfers generated methods such as .readByQuery() or .ListByQuery()
   view plainprintabout
 <cfset query = getTransfer().listbyQuery(query) />
 <cfdump var="#query#" />
That's it. Nothing really new hear and like I said you can get all of this from the documentation. There are some limits still to TQL, one of the is using TOP/LIMIT (see this thread). In my next post i'll go into passing values to the TQL statement and look at other methods that can effect how the TQL script is resolved by Transfer Quick reference points:
TweetBacks
Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
nick tong's Gravatar TQL is sweet. I've loved working with it, i even wrote a fusebox lexicon for it: http://www.succor.co.uk/index.cfm/2007/7/15/TQL-Tr...
# Posted By nick tong | 10/23/07 1:39 AM
Brian Rinaldi's Gravatar Just as an FYI, the included Transfer template on my Illudium PU-36 Code Generator actually generates a generic gateway component utilizing TQL.
# Posted By Brian Rinaldi | 10/23/07 6:22 AM
BlogCFC / created by Raymond Camden / running version 5.9.5.003 / Contact AndyJarrett.com / Pet Rescue SOS www.redgiraffes.co.uk