Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Provide an improved syntax for projections #579

@patrick-steele-idem

Description

@patrick-steele-idem

Examples of improvements:

QUERY:

select {
    count as totalCount,
    searchResult.items as items[{
        itemId as id, 
        label as label,
        primaryCategory.categoryName as categoryName,
        shippingInfo {
            shippingType,
            shipToLocation
        }
    }]
}
from finding

OUTPUT:

{
    totalCount: 100,
    items: [
        {
            id: 12345,
            label: 'Test',
            categoryName: 'Athletic',
            shippingInfo: {
                shippingType: "Calculated",
                shipToLocation: "US"
            }
        },
        ...
    ]
}

Also, an "anonymous" top-level array could be returned by dropping the label for "searchResult.items" as shown in the following query:

QUERY:

select searchResult.items as [{
    itemId as id, 
    label,
    primaryCategory.categoryName as categoryName,
    shippingInfo {
        shippingType,
        shipToLocation
    }
}]
from finding

OUTPUT:

[
    {
        id: 12345,
        label: 'Test',
        categoryName: 'Athletic',
        shippingInfo: {
            shippingType: "Calculated",
            shipToLocation: "US"
        }
    },
    ...
]

Also, I think a limit on any arrays should be supported. For example:

QUERY:

select {
    count as totalCount,
    searchResult.items as items[limit=5, {
        itemId as id, 
        label as label,
        primaryCategory.categoryName as categoryName,
        shippingInfo {
            shippingType,
            shipToLocation
        }
    }]
}
from finding

Also, user functions for controlling property values would be helpful as well. For example:

QUERY:

var formatCurrency = require('utils/formatting').formatCurrency; 

select {
    totalCount,
    searchResult.items as items[{
       formatCurrency(buyItNowPrice.$t, buyItNowPrice.currencyId) as buyItNowPrice
    }]
}
from finding

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions