Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sql Server FOR JSON support #317

Open
JocaPC opened this issue Sep 21, 2015 · 5 comments
Open

Sql Server FOR JSON support #317

JocaPC opened this issue Sep 21, 2015 · 5 comments
Labels
feature-request Follow up Recent question asked by tedious members for old issues or discussion that requires member input

Comments

@JocaPC
Copy link

JocaPC commented Sep 21, 2015

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:

  1. 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.
  2. 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.

@spanditcaa
Copy link
Member

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
Copy link
Author

JocaPC commented 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
Copy link
Collaborator

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
Copy link

manu-st commented Jan 26, 2017

Any update on the JSON support from SQL Server 2016?

@jovanpop-msft
Copy link

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.

@IanChokS IanChokS added feature-request Follow up Recent question asked by tedious members for old issues or discussion that requires member input labels Dec 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Follow up Recent question asked by tedious members for old issues or discussion that requires member input
Projects
None yet
Development

No branches or pull requests

6 participants