Skip to content

Commit

Permalink
document how to use sub-parts of Photon.js queries
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolasburk committed Dec 17, 2019
1 parent 7f8b064 commit e6198b5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/photon/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Photon is a type-safe database client auto-generated based on your [data model d
- [API Reference](#api-reference)
- [Filtering](#filtering)
- [Debugging](#debugging)
- [Reusing query sub-parts](#reusing-query-sub-parts)
- [Managing connections](#managing-connections)

## Overview
Expand Down Expand Up @@ -543,6 +544,19 @@ const photon = new Photon({
})
```

## Reusing query sub-parts

You can reuse subparts of a Photon.js query by not immediately evaluating the promise that's returned by any Photon.js API call. Depending on your evaluating the promise, you can do this either by leaving out the prepended `await` keyword or the appended call to `.then()`.

```ts
// Note the missing `await` here.
const currentUserQuery = photon.users.findOne({ where: { id: currentUserId } })

// Now you have the sub-part of a query that you can reuse.
const postsOfUser = await currentUserQuery.posts()
const profileOfUser = await currentUserQuery.profile()
```
## Managing connections
Photon connects and disconnects from your data sources using the following two methods:
Expand Down

0 comments on commit e6198b5

Please sign in to comment.