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

docs: adding working with data pages #4970

Merged
merged 8 commits into from
Apr 14, 2020
Merged

docs: adding working with data pages #4970

merged 8 commits into from
Apr 14, 2020

Conversation

agnes512
Copy link
Contributor

@agnes512 agnes512 commented Mar 25, 2020

Closes #2527

Checklist

👉 Read and sign the CLA (Contributor License Agreement) 👈

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈




## NOT SURE IF THE FOLLOWINGS ARE CORRECT IN LB4
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if the blow is true for LB4.

Copy link
Contributor

Choose a reason for hiding this comment

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

Better to not include it if it doesn't work for sure, imo, could open a follow-up issue for them?

docs/site/Fields-filter.md Outdated Show resolved Hide resolved
docs/site/Fields-filter.md Outdated Show resolved Hide resolved
docs/site/Fields-filter.md Outdated Show resolved Hide resolved
In LoopBack 4, models describe the shape of data, repositories provide behavior
like CRUD operations, and controllers define routes (this is different from
LoopBack 3.x where models implement behavior too). LB4
[repositories](Repository.md) provide a couple of create, read, update, and
Copy link
Member

Choose a reason for hiding this comment

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

do the CRUD operations only available for the CRUDRepository?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think for now all LB4 repositories are extended from DefaultCrudRepository, and it provides those CRUD operations mentioned here. If this is true, then I think the answer is yes.

Copy link
Member

Choose a reason for hiding this comment

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

cuz i'm thinking Repository doesn't need to have CRUD, so that's why we might want to leave it for a broader usage.

docs/site/Querying-data.md Outdated Show resolved Hide resolved
docs/site/Fields-filter.md Show resolved Hide resolved
docs/site/Fields-filter.md Outdated Show resolved Hide resolved
docs/site/Fields-filter.md Outdated Show resolved Hide resolved
docs/site/Fields-filter.md Outdated Show resolved Hide resolved
docs/site/Fields-filter.md Outdated Show resolved Hide resolved
docs/site/Querying-data.md Outdated Show resolved Hide resolved
docs/site/Querying-data.md Outdated Show resolved Hide resolved

```
/cars?filter[where][odo][lt]=30000
Copy link
Member

Choose a reason for hiding this comment

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

i know it's not part of the LB3 docs either. It might be helpful to "join" the two conditions. e.g. what should be the where clause if the value ranges from 10000 and 30000. It's out of scope of this PR though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, I think Rifa mentioned it before. I think Querying-data.md will be a good place to introduce the function.


```ts
await productRepository.find({where: {size:'large'}});
Copy link
Member

Choose a reason for hiding this comment

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

Just a question.. in the controller, we can create WhereBuilder or FilterBuilder as an argument. Does it work if we provide the JSON? If yes, perhaps we can list both? Again, I'm good to leave it out of scope for this PR and limit to "translating" the LB3 docs to LB4.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it works with JSON. Will have examples in where-filter.md too.

Copy link
Contributor

@nabdelgadir nabdelgadir left a comment

Choose a reason for hiding this comment

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

just some suggestions/nitpicks


{% include code-caption.html content="REST" %}

{% include warning.html content="
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you mentioned this above, maybe you don't need to mention it again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reworded.

docs/site/Fields-filter.md Outdated Show resolved Hide resolved
docs/site/Fields-filter.md Outdated Show resolved Hide resolved
docs/site/Fields-filter.md Outdated Show resolved Hide resolved
docs/site/Include-filter.md Outdated Show resolved Hide resolved



## NOT SURE IF THE FOLLOWINGS ARE CORRECT IN LB4
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to not include it if it doesn't work for sure, imo, could open a follow-up issue for them?

docs/site/Skip-filter.md Outdated Show resolved Hide resolved
docs/site/Where-filter.md Outdated Show resolved Hide resolved
docs/site/Where-filter.md Outdated Show resolved Hide resolved
docs/site/Where-filter.md Outdated Show resolved Hide resolved

## Overview

A _query_ is a read operation on models that returns a set of data or results.
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't they write too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the query here means the query we use for the GET request, where these filters can be applied. Do you have any suggestions?

Note that to include more than one field in REST, use multiple filters.

You can also use [stringified JSON format](Querying-data.html#using-stringified-json-in-rest-queries) in a REST query.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a URL example of stringified JSON format for fields filter here? It would be very helpful for our readers to see an example right here without having to navigate away to the link where they will actually see an example for the where filter. Let the link be there, though. Small thing, but makes a big difference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for reminding me! I just realized that the url works well with the stringified JSON ( it has a bug with pure url, see #4992). It will be a good workaround for fields!

?filter={"where":{"or":[{"id":1},{"id":2},...,{"id":20"},{"id":21}]}}
```

<!-- DOES NOT WORK IN LB4
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this commented code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I tested, this doesn't work in LB4, but we might want similar features in LB4. I use the comment as a reminder.

Copy link
Contributor

@nabdelgadir nabdelgadir left a comment

Choose a reason for hiding this comment

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

LGTM 👍

docs/site/Fields-filter.md Outdated Show resolved Hide resolved
docs/site/Querying-data.md Show resolved Hide resolved
docs/site/Querying-data.md Outdated Show resolved Hide resolved
docs/site/Querying-data.md Outdated Show resolved Hide resolved
docs/site/Querying-data.md Outdated Show resolved Hide resolved
level. There are three options:
- 'nullify': Set `undefined` to `null`
- 'throw': Throw an error if `undefined` is found
- 'ignore': Remove `undefined`. This is the default behavior if `normalizeUndefinedInQuery`
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean by "Remove undefined"? Could be helpful to show examples of the results in the two snippets below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This part is commented out as I am confused too 😅 so I am leaving them for future.

docs/site/Querying-data.md Outdated Show resolved Hide resolved
docs/site/Querying-data.md Outdated Show resolved Hide resolved
docs/site/Querying-data.md Outdated Show resolved Hide resolved
docs/site/Querying-data.md Outdated Show resolved Hide resolved
@agnes512 agnes512 force-pushed the data branch 4 times, most recently from 1a12e82 to b74440b Compare April 14, 2020 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docs: Add "Working with Data" section
4 participants