Skip to content

Commit 3cff1f3

Browse files
committed
add docs titles for llms.txt, fixup referential variable docs
1 parent 0db84aa commit 3cff1f3

File tree

11 files changed

+112
-5
lines changed

11 files changed

+112
-5
lines changed

packages/docs/src/pages/client/web-worker-client.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
description: How to run Triplit in a Web Worker - useful for multi-tab offline support and reducing main thread workload.
3+
---
4+
15
# Web Worker Client
26

37
Triplit supports running the client in a Web Worker (specifically, a [`SharedWorker`](https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker), which can connect to multiple tabs running a script from the same domain). While running a Web Worker, data syncs between browser tabs without having to sync with server. This reduces network traffic for Triplit apps running in the multiple tabs, move Triplit local database computation to a separate thread, and allow for robust multi-tab offline support.

packages/docs/src/pages/frameworks/react-native.mdx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,36 @@ For more information on setting up an Expo project with typescript see the [Expo
2727

2828
Next, install Triplit's packages:
2929

30+
<Callout type="warning">
31+
There is currently a bug in how Triplit handles optional dependencies in
32+
Metro, so you will need to install `uuidv7` as a dependency in your project.
33+
This is a temporary workaround until the bug is fixed.
34+
</Callout>
35+
3036
<Tabs items={['npm', 'pnpm', 'yarn', 'bun']}>
3137
<Tab>
3238
```bash copy
33-
npm i @triplit/client @triplit/react-native
39+
npm i @triplit/client @triplit/react-native uuidv7
3440
npm i @triplit/cli --save-dev
3541
```
3642
</Tab>
3743
<Tab>
3844
```bash copy
39-
pnpm add @triplit/client @triplit/react-native
45+
pnpm add @triplit/client @triplit/react-native uuidv7
4046
pnpm add @triplit/cli --save-dev
4147
```
4248

4349
</Tab>
4450
<Tab>
4551
```bash copy
46-
yarn add @triplit/client @triplit/react-native
52+
yarn add @triplit/client @triplit/react-native uuidv7
4753
yarn add @triplit/cli --dev
4854
```
4955

5056
</Tab>
5157
<Tab>
5258
```bash copy
53-
bun add @triplit/client @triplit/react-native
59+
bun add @triplit/client @triplit/react-native uuidv7
5460
bun add @triplit/cli --dev
5561
```
5662

packages/docs/src/pages/query/subquery.mdx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,25 @@ A given entity in the result will look like this:
8080
}
8181
*/
8282
```
83+
84+
## Use with relational queries
85+
86+
The examples above are hardcoded to a specific user ID, however you can use [referential variables](/query/variables#referential-variables) to make the subquery dynamic. For example:
87+
88+
```typescript
89+
// Fetch all 747 planes that have a flight to an airport newer than the plane
90+
const query = client.query('planes').Where([
91+
['model', '=', '747']
92+
{
93+
exists: client.query('flights').Where([
94+
['plane_id', '=', '$1.id'],
95+
{
96+
exists: client.query('airports').Where([
97+
['id', '=', '$1.destination_id']
98+
['created_at', '>', '$2.created_at'],
99+
]),
100+
},
101+
]),
102+
},
103+
]);
104+
```

packages/docs/src/pages/query/variables.mdx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,39 @@ Token variables are prefixed with the `token` scope and are accessible to all qu
4343

4444
When determining access control rules with [roles](/schemas/permissions#roles), you can use role variables to reference values from a client's token in your permission definitions. Role variables are prefixed with the `role` scope.
4545

46+
### Referential variables
47+
48+
When issuing a subquery to load related data, you can use a referential variable in your query to reference ancestral data in the query. Referential variables are prefixed with a number (e.g. `$1`, `$2`, etc.) and correspond to higher levels of the query. If you are coming from a SQL background, you can think of these variables referencing the join keys of the parent.
49+
50+
For example, you may fetch all posts and include the author of each post in the result:
51+
52+
```typescript
53+
const query = client.query('posts').SubqueryMany(
54+
'postAuthors',
55+
client.query('users').Where(['id', '=', '$1.authorId']) // $1.authorId refers to posts.authorId
56+
);
57+
```
58+
59+
By default, `$1` will actually be applied automatically if you do not specify a variable prefix `$authorId` in the filter. However, you would be required to use the referential prefix if you wanted to reference a grandparent or higher in the query:
60+
61+
```typescript
62+
// Fetch all 747 planes that have a flight to an airport newer than the plane
63+
const query = client.query('planes').Where([
64+
['model', '=', '747']
65+
{
66+
exists: client.query('flights').Where([
67+
['plane_id', '=', '$1.id'],
68+
{
69+
exists: client.query('airports').Where([
70+
['id', '=', '$1.destination_id']
71+
['created_at', '>', '$2.created_at'],
72+
]),
73+
},
74+
]),
75+
},
76+
]);
77+
```
78+
4679
## Accessing variables
4780

4881
`$global` and `$token` variables are accessible on the client instance through the `vars` property.

packages/docs/src/pages/schemas/relations.mdx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,22 @@ const departmentsQuery = client.query('departments').Include('classes');
124124

125125
## Defining relations with referential variables
126126

127-
TODO
127+
You can also define relations ad-hoc in a query using referential variables. This allows you to define relations that are not part of the schema and is equivalent to a `JOIN` you might see in SQL. Under the hood, this is actually what your `RelationMany`, `RelationOne`, and `RelationById` attributes are doing. See usage of referential variables in the [Variables](/query/variables#referential-variables) documentation. For example:
128+
129+
```typescript
130+
// Fetch all 747 planes that have a flight to an airport newer than the plane
131+
const query = client.query('planes').Where([
132+
['model', '=', '747']
133+
{
134+
exists: client.query('flights').Where([
135+
['plane_id', '=', '$1.id'],
136+
{
137+
exists: client.query('airports').Where([
138+
['id', '=', '$1.destination_id']
139+
['created_at', '>', '$2.created_at'],
140+
]),
141+
},
142+
]),
143+
},
144+
]);
145+
```

packages/docs/src/pages/self-hosting/docker.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
description: Learn how to run Triplit in a Docker container.
3+
---
4+
15
# Docker
26

37
Triplit publishes the following Docker images that run in the following environments:

packages/docs/src/pages/self-hosting/key-gen.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
description: Learn how to generate keys and tokens for Triplit authentication.
3+
---
4+
15
# Key and Token Generation
26

37
This page will help you generate the keys needed to run a self-hosted Triplit server. You will need to generate a signing key and a public key, which are used to sign and verify tokens for authentication. This is unopinionated on where you store your keys.

packages/docs/src/pages/self-hosting/platform-guides/fly.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
description: Learn how to deploy Triplit on Fly.io.
3+
---
4+
15
import { Steps } from 'nextra/components';
26

37
# Deploying to Fly.io

packages/docs/src/pages/self-hosting/platform-guides/railway.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
description: Learn how to deploy Triplit on Railway.
3+
---
4+
15
import { Steps, Callout } from 'nextra/components';
26

37
# Deploying to Railway

packages/docs/src/pages/ssr.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
description: Learn how to use Triplit in a server-side rendering environment, like SvelteKit, Next.js, or Remix.
3+
---
4+
15
# Server-side rendering
26

37
Triplit is designed to work in a client-side environment, but it can work in a server-side rendering (SSR) environment as well.

0 commit comments

Comments
 (0)