Domanda

We currently use CF8 and don't have access to any ORM functionality. However, I'm hoping someone out there can give me any tips on how to create all my crud actions more quickly than we are doing them right now.

Right now we create a cfc with the functions we need for each new component, hardcoded all the db field names into each function which feels like it takes forever to do. Unfortunately the bosses wont allow us to use anything like CFWheels and we are forever creating each function manually.

I'm not looking for the scripts to self create based on what's in the DB, just a quicker way of creating the necessary crud actions for any script we write.

Below is a basic function we write for all out apps.. So I'm hoping someone out there can give me some pointers on creating all these things much more quickly.

<cfcomponent extends="master.cfc">
    <cffunction name="users" access="public" returntype="query">
    <cfargument name="dsn" type="string" required="yes">
    <cfargument name="id" type="numeric" required="yes">

    <cfquery name="get_users" datasource="#arguments.dsn#">
    SELECT ID,firstname,lastname,email
    FROM users
    WHERE ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.id#">
    </cfquery>

    <cfreturn get_users >
    </cffunction>
</cfcomponent>
È stato utile?

Soluzione

I prefer DataMgr for CRUD. It is compatible with many CF versions and database engines. It automatically applies cfqueryparam, too.

Example query using DatMgr:

<cfset get_users = Application.DataMgr.getRecords("users", {id: arguments.id})>

This doesn't replace your CFC, but it might save you same typing. I've found it especially helpful for insert and update actions.

Altri suggerimenti

Have you tried CFBuilder?

Use Adobe CFC Generator (in ColdFusion Builder 2.0) -> Create CFC

http://help.adobe.com/en_US/ColdFusionBuilder/2.0/Using/WS0ef8c004658c1089-1b4fc34c122964e1318-8000.html

I have not used Woodi, but I used Illudium PU-36 Code Generator @ http://cfcgenerator.riaforge.org/ back in the CF7/8 days and it worked well.

At first glance, what I feel is you need a code generator. Try Woodi.

Also,

Say if you a table called 'user', create two components.

  1. user.cfc
  2. w_user.cfc

user extends w_user. This way, always put your code generator code in 'w_user' and any customization in code in the 'user'. So, your MODEL object will be just the 'user.cfc'.

Ex: Getting User records

let the function be named as 'get_users()'. This can be generated with Woodi. So, the code should be in w_user cfc.

While you may have a case where you need some filter on it. Lets call it get_userWithFilter(). This will be in the 'user'. Now, You can be referring to the 'get_users()' function from inside this function.

If you have no filters needed, then you can directly call the get_users() function from 'user.cfc' (available by inheritance).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top