Allow adding "AS" alias to jsonb fields
Summary
Currently, when you want to select a nested property from a jsonb object, you can add an alias to it only via "exprs" option.
Example
Database setup
CREATE TABLE things (
id SERIAL PRIMARY KEY,
notBody jsonb
);
Code demonstrating the behavior
db.things.find(
{
'notBody.firstNestedObject.secondNestedObject.someProperty !=': 'undesirable_value',
},
{
exprs: {
someProperty: `"notBody"#>>'{firstNestedObject,secondNestedObject,someProperty}'`,
},
},
);
This produces an SQL request like this one (no problem with the request, this is expected):
SELECT "notBody"#>>'{firstNestedObject,secondNestedObject,someProperty }' AS "someProperty" FROM "things"
WHERE "notBody"#>>'{firstNestedObject,secondNestedObject,someProperty}' <> 'undesirable_value'
Expected behavior
Maybe something like this should produce the same SQL result. Otherwise you should always think about how will Massive transform criteria property and use that in exprs, so using similar access to nested properties in both criteria and options.fields seems reasonable.
db.things.find(
{
'notBody.firstNestedObject.secondNestedObject.someProperty !=': 'undesirable_value',
},
{
fields: [
'notBody.firstNestedObject.secondNestedObject.someProperty AS someProperty',
],
},
);
Additional info
Currently example from "Expected behavior" will make a conversion from "notBody.firstNestedObject.secondNestedObject.someProperty" to ""notBody"#>>'{firstNestedObject,secondNestedObject,someProperty }'", but "AS" will be ignored, so column will be loaded under the name of "?column?".