开发者

In Coldufsion, is it better to return query data in a struct or the query?

开发者 https://www.devze.com 2023-03-20 19:59 出处:网络
Simple question today: Is it better to return query data in a struct or return the query itself? This is in context of displaying the information in a readable format. (Typical data system.) I have do

Simple question today: Is it better to return query data in a struct or return the query itself? This is in context of displaying the information in a readable format. (Typical data system.) I have done it by query till now, however I was thinking about making a async. sortin开发者_如何学运维g function (like an arrow on the top of a column). Would it better to put the query into a struct and then have sorting functions on the struct...or would it just be better to re-query the information? I'm thinking it would be better to do the struct, especially with large data...comments?

Is there a way to sort queries as they come?

Note: I don't want to use CFGrid...for learning purposes and other reasons.


ColdFusion returns a dataset that you can reference directly, I see no reason to waste time dumping it into a struct.

If you don't want to run the query a 2nd time, you can always run a query of queries and just resort the data that way.


Returning the query would make the function more reusable. If you need it in a particular format, write a function that returns the data in that particular format, but internally that method would call the original function to get the query data.

public query function getData() {
    ...
    return myQuery;
}

public struct function getDataForGrid() {
    var data = getData();
    ...
    return myStruct;
}

On the 2nd method you could also do a returntype of "any" and return whatever datatype you need.

The first method could also be declared private if you don't ever intend to access the query data directly.


Remember that a query object is basically a struct of array's already :

queryName.fieldName[rowNumber]
0

精彩评论

暂无评论...
验证码 换一张
取 消