Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    • Switch to GitLab Next
  • Sign in / Register
M
massive-js
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 10
    • Issues 10
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 2
    • Merge requests 2
  • Requirements
    • Requirements
    • List
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Container Registry
  • Analytics
    • Analytics
    • CI/CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Dian Fay
  • massive-js
  • Issues
  • #706

Closed
Open
Created Jan 29, 2020 by PizzaPartyInc@PizzaPartyInc

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?".

Edited Jan 29, 2020 by PizzaPartyInc
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None