Has anyone ever noticed the `queryColumnData()` fu...
# lucee
b
Has anyone ever noticed the
queryColumnData()
function has a
closure
argument. I never had. The argument shows in cfdocs.org/querycolumndata, but with no explanation at all. The docs.lucee.org/reference/functions/querycolumndata.html#argument-closure page simply says
UDF/Closure that call with the values from column
which is a little vague. Some testing appears to show that this closure can be used map the array by returning a different value which overrides the value taken from the column. For instance, this would upper case all the values from this column in the final array
Copy code
myQuery
  .columnData( 'name', (data)=>data.ucase() );
but I'm really wondering why this exists. CFML already has a construct called
arrayMap()
which seems sufficient if I want to massage all the values of an array
Copy code
myQuery
  .columnData( 'name' )
  .map( (data)=>data.ucase() );
I'm just not clear why
queryColumnData()
needed this as there's certainly no precedent set that any BIF that returns an array also has an inbuilt closure argument for also mapping that array.
s
I’m curious does one actually modify the query in place vs. a new instance of the data?
Never mind
z
@pothys-mitrahsoft can you add a test case for this?
šŸ‘ 1
p
ok zac
a
TBH I would mark this param as deprecated, and remove it from the docs. The function is for getting the query column data. Not for monkeying with it. As Brad says: there's already
map
for that.
I think there's possibly a bit of a transparency/process issue here when it comes to features being added. There is no Jira ticket for the creation of
queryColumnData
, so it's not possible to see how the requirements for it were fleshed out. Or does LAS have some other internal issue tracker that covers all this?
z
we use radar!
there was the old railo / jboss jira, but alas the old project got nuked recently and we don't have a backup
šŸ‘ 1
p
I got some history from Railo Github ( https://github.com/getrailo/railo ) As per the below commits on Railo, The arrayMap() was implemented in 2014 https://github.com/getrailo/railo/commit/ebae84bed467b2e71f2d79804806247d3c8fac10 But the queryColumnData() were already implemented in 2012 before the arrayMap() https://github.com/getrailo/railo/commit/7d8c7c7760ca5566eff9213272626e854385a8c2
⭐ 2
a
But the queryColumnData() were already implemented in 2012 before the arrayMap
Ah! That makes sense then. Cheers for the clarification. I still stick with my suggestion of doing the deprecation, and pointing ppl to
arrayMap
instead. But as far as suggestions go, it's not worth anyone losing any sleep over.
Hrm. That initial implemented nailed the requirement. Looks like the callback param was added later. Also interesting that this whole things started as a feature request raised by... me (https://groups.google.com/g/railo/c/23hlmO-aWSA). Look, never mind. it's not worth doing too much investigation on. We are where we are, anyhow.
b
@pothys-mitrahsoft Thanks for digging up the history on that.
šŸ‘ 1