Quantcast
Channel: Lucee Dev - Latest topics
Viewing all articles
Browse latest Browse all 419

New Query Return Type

$
0
0

So not exactly earth shattering, but I’ve encountered this scenario often enough I thought it worth bringing up. Often when returning data from a query that will be used either for an API, or to pass through to the browser, I’ll use FOR JSON/XML PATH to have the database serialize the return data. There are many times where this is more efficient rather than having to return the query data structure, and then serialize it in Lucee, before returning it to the caller. This results in the query returning a single row, with a single column with a randomized name.

My thought then was to add a new return type to the query called “scalar” (or something to that effect),
and when used, the query variable will simply be the first cell. If the query tries to returns more than one column, or one row, it would throw an error

<cfquery name="json_out" datasource="..." returntype="scalar">
	SELECT TOP(2) o.id, o.date
	FROM orders o
	FOR JSON PATH
</cfquery>
<cfdump var='#json_out#'>

Output would be something like

[{"id":"998","date":"2023-10-01 09:31"},{"id":"997","date":"2023-09-29 13:41"}]

5 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 419

Trending Articles