[Suggestion] JSON output for .find() with raw & include
See original GitHub issueWhat you are doing?
Use .find() with raw & include.
Post.findAll({
raw: true,
include: [Tag]
});
What do you expect to happen?
{id: 1, ..., Tag: {id: 1, ...}}
What is actually happening?
{id: 1, ..., 'Tag.id': 1, ...}}
Suggestion
As postgres 9.2 added row_to_json
function, raw query can be constructed as:
SELECT "Posts".*, row_to_json("Tags".*) AS "Tag" FROM "Posts" INNER JOIN "Tags" ON ("Posts".tid = "Tags".id);
which give the expected JSON result and should improve .find() performance.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:18
- Comments:11 (4 by maintainers)
Top Results From Across the Web
How can I include raw JSON in an object using Jackson?
Object', since this should work ok: for serialization, String will be output as is, and for deserialization, it will be deserialized as a...
Read more >JSON methods, toJSON
The JSON (JavaScript Object Notation) is a general format to represent values and objects. It is described as in RFC 4627 standard.
Read more >JSON formatting with jq and CI/CD linting automation | GitLab
Learn how to filter in JSON data structures and interact with the REST API. Use the GitLab API to lint your CI/CD configuration...
Read more >Format Query Results as JSON with FOR JSON - SQL Server
Use the FOR JSON clause to simplify client applications by delegating the formatting of JSON output from the app to SQL Server.
Read more >Reshaping JSON with jq
After each query in this lesson, I will include the first few lines of the expected results, so that you can check your...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This problem should be as early does not exist
For me on MySQL, it will be a major performance boost. Hope you will address it.
It seems that all major DB have this feature now. JS is slow compare to native DB function.
A first step could be to just use JSON_OBJECT at first level to give the the same results as now but on the DB side.
Exemple : SELECT JSON_OBJECT( ‘lastName’, lastName, ‘firstName’, firstName ) FROM users;
=>
[{“lastName”: “Cell”, “firstName”: “Ance”} {“lastName”: “Laure”, “firstName”: “Varner”}]