Skip to content

Add the Posts example to illustrate a use for $lookup - #8

Open
drpicox wants to merge 1 commit into
jsonata-js:masterfrom
drpicox:master
Open

Add the Posts example to illustrate a use for $lookup#8
drpicox wants to merge 1 commit into
jsonata-js:masterfrom
drpicox:master

Conversation

@drpicox

@drpicox drpicox commented Mar 17, 2020

Copy link
Copy Markdown

This adds an example based on the recommendations for a redux state shape:

I have added this because I believe that a good example of $lookup should be beneficial.
The added query is:

(
    $comment := function($cid) {( comments.byId.$lookup($cid) )};
    $post := function($pid) {( posts.byId.$lookup($pid) )};
    posts.allIds{$: $post($).comments.$comment($)}
)

@andrew-coleman andrew-coleman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good, but I would have used the following expression for the same effect:

posts.allIds@$P{
    $P: byId.$lookup($P).comments.$lookup($$.comments.byId, $)
}

alternatively, if you can assume that the list of post IDs in posts.allIds is the same as the entries in posts.byId (and I'm happy if you can't assume this) then you could simplify it:

posts.byId.*{
    id: comments.$lookup($$.comments.byId, $)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants