Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

drpicox
Copy link

@drpicox drpicox commented Mar 17, 2020

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($)}
)

Copy link
Member

@andrew-coleman andrew-coleman left a comment

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