Repository navigation
Description
Sql Server CTP2 enables developers to format Sql query result set as JSON text (see https://msdn.microsoft.com/en-us/library/dn921882.aspx). We just need to add FOR JSON clause after any query, e.g.:
SELECT *
FROM tab1
WHERE col1 = 4
ORDER BY col2
FOR JSON PATH
Are there some plans to add support for this clause in tedious? In this case we don't need to read rows/cells from result - we can just take entire JSON result object.
Some implementation details:
- FOR JSON result set will have exactly one column with name "JSON_F52E2B61-18A1-11d1-B105-00805F49916B". The name of that column will be same in every FOR JSON query.
- JSON is not returned as a single cell because we might have big text. Generated JSON text will be split into 2-4K chunks and returned as set of rows with a single column (see Output of the FOR JSON clause in https://msdn.microsoft.com/en-us/library/dn921882.aspx ). Therefore, cells should be concatenated before they are returned as JSON object.
I have tried to execute FOR JSON query with tedious and it works fine; however, I need to concatenate all chunks as a single text in on-row event handler.
It is not a big problem; however, it would be nice to have built-in function/event handler that returns all concatenated chunks as a single JSON object. Maybe to have new event (e.g. on("json", function(json) { ... } ) ) where event handler function will have concatenated chunks as a valid JSON object.
Since it already works fine it seems to me that this concatenation of results could be just a little enhancement that adds a full support.
Activity
spanditcaa commentedon May 6, 2016
Since it seems to be a popular platform for tedious users, just wanted to note that FOR JSON is available in SQL Azure as well. https://azure.microsoft.com/en-us/blog/json-functionalities-in-azure-sql-database-public-preview/
Built in handling for tedious would be a great addition.
JocaPC commentedon May 6, 2016
Interesting thing is that node-mssql has JSON support only if it is used with tedious: http://patriksimek.github.io/node-mssql/#json
patriksimek commentedon May 6, 2016
JSON support was limited to Tedious due to experimental phase. I was curious about the feedback on the implementation. All the logic behind this lays in node-mssql so I added support for additional drivers in 3.3.0.
manu-st commentedon Jan 26, 2017
Any update on the JSON support from SQL Server 2016?
jovanpop-msft commentedon Mar 11, 2017
In SQL Server GitHub samples you can find example RESP API that has some wrapper around tediuos that leverages FOR JSON: https://github.com/Microsoft/sql-server-samples/tree/master/samples/features/json/todo-app/nodejs-express4-rest-api The biggest missing piece is a function that streams results from sql query into some output stream. In this sample is added wrapper function on top of tedious that gets results from Request and on each 'row' event push part of the received JSON into the output stream.
FOR JSON in SQL Server splits output JSON into 2KB chunks so this is ideal case for output stream. I think that one function that will natively stream chunks from request into stream would be the core feature in REST API implementation, especially in Azure.