Model Glue Tips Part 4: Use Generic Database Messages to speed up your development

Posted by Mark Drew on code on August 13, 2007

Tagged under model-glue

A lot of the time that you are developing an application, depending on how you have set up your database etc, you will want to do a “select * from sometable”, for example to get the types of pages you have, or a full list of user roles or simply to get the current user. This is all fine if you are sticking to the semi rigid pattern of having services for your whole architecture, but in the heat of battle, you might be tempted to do a cfquery in your view. DONT!

Model-Glue gives you a built-in way of doing Generic Database actions (or messages as they are called in the documentation)

The messages that you can call from the broadcast section of your event handler are:

  • modelglue.GenericList: Which does a select * from [table]
  • modelglue.GenericRead: Which does a select * from [table] where [id] = xyz
  • modelglue.GenericCommit: Which will save the record (or update it depending if it already exists with that ID)
  • modelglue.GenericDelete: Which will delete the record with the ID that you have passed in

An example of using modelglue.GenericList would be to list the People in our fictional system.

In ModelGlue_people.xml I create an event-handler to display people:

	<view>
</event-handler> </code>

Then in my display template I can get access to the query:

<cfdump var="#viewstate.getValue("qPeopleList")#"/>

</code>

There is more functionality available such as filtering and sorting, you can check out the details in the Documentation for modelglue.GenericList

Calling the other other Generic Database functions is as simple as that, have a look at the full documentation over at http://docs.model-glue.com/ under “How To’s” / “How To Use Generic Database Messages”




comments powered by Disqus