Improving QueryNew(struct, data)

the syntax for queryNew is a bit ugly and leads to hard to maintain code due to
the need to maintaining two separate arrays or lists to specify columns and data types

being able to pass in a struct which defines the columns and datatype would be a lot
clearer and easier to maintain

queryNew("name,age","varchar,numeric",[["Susi",20],["Urs",24]]); 

vs

queryNew({"name"="varchar","age"="numeric"},[["Susi",20],["Urs",24]]); 

+1

i personally never use queryNew to create a populated query, because it is to complicated.
i use the function query instead:
qry=query('lastname':['Sorglos','Chlous'],'firstname':['Susi','Sami']);

When you are asking yourself why we have 2 functions doing the same in different ways, the answer is simple.
Compatibility, we added Query with Railo 1.0 long before queryNew had this functionality, then when ACF added this functionality we had to follow.

I get your point, but i PERSONALLY see that function only as a must have and because of that not worth extending it beyond the ACF functionality. If you don’t care about compatibility to ACF, use Query.

If you don’t care about compatibility to ACF, use Query.

Anyone looking to use the proposed new function signature would be breaking compatibility regardless. The documentation is unsurprisingly terrible for query(), though.

Oh, I wasn’t aware of query() and yes the docs are a shocker!

Does the syntax for query() even allow specifying datatypes? It’s rather important for QoQs

Well,how about createQuery(struct, data) which is also more consistent with existing CFML functions

(aside, can anyone point to an example of how to reference other similar functions in the docs)

The documentation is open-sourced at GitHub - lucee/lucee-docs: Source and build scripts for Lucee's documentation. . If you find something to be “unsurprisingly terrible” then please take a moment and help improve it.

Thank you.

There is literally no documentation for this tag. Which is especially bad if it has been in since Railo 1!

I have put a submission that hopefully helps a bit

1 Like