Improving QueryNew(struct, data)


#1

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]]); 

http://docs.lucee.org/reference/functions/querynew.html


#2

+1


#3

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.


#4

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.


#5

Oh, I wasn’t aware of query() and yes the docs are a shocker!
http://docs.lucee.org/reference/functions/query.html

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)


#6

The documentation is open-sourced at https://github.com/lucee/lucee-docs/ . If you find something to be “unsurprisingly terrible” then please take a moment and help improve it.

Thank you.


#7

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