@tanstack/angular-db 0.1.62 → 0.1.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/skills/angular-db/SKILL.md +70 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/angular-db",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.64",
|
|
4
4
|
"description": "Angular integration for @tanstack/db",
|
|
5
5
|
"author": "Ethan McDaniel",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"skills"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@tanstack/db": "0.6.
|
|
43
|
+
"@tanstack/db": "0.6.4"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"@angular/core": ">=16.0.0",
|
|
@@ -182,6 +182,76 @@ Angular 16 structural directives:
|
|
|
182
182
|
<li *ngFor="let todo of query.data(); trackBy: trackById">{{ todo.text }}</li>
|
|
183
183
|
```
|
|
184
184
|
|
|
185
|
+
## Includes (Hierarchical Data)
|
|
186
|
+
|
|
187
|
+
When a query uses includes (subqueries in `select`), each child field is a live `Collection` by default. Subscribe to it with `injectLiveQuery` in a child component:
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
@Component({
|
|
191
|
+
selector: 'app-project-list',
|
|
192
|
+
standalone: true,
|
|
193
|
+
imports: [IssueListComponent],
|
|
194
|
+
template: `
|
|
195
|
+
@for (project of query.data(); track project.id) {
|
|
196
|
+
<div>
|
|
197
|
+
{{ project.name }}
|
|
198
|
+
<app-issue-list [issuesCollection]="project.issues" />
|
|
199
|
+
</div>
|
|
200
|
+
}
|
|
201
|
+
`,
|
|
202
|
+
})
|
|
203
|
+
export class ProjectListComponent {
|
|
204
|
+
query = injectLiveQuery((q) =>
|
|
205
|
+
q.from({ p: projectsCollection }).select(({ p }) => ({
|
|
206
|
+
id: p.id,
|
|
207
|
+
name: p.name,
|
|
208
|
+
issues: q
|
|
209
|
+
.from({ i: issuesCollection })
|
|
210
|
+
.where(({ i }) => eq(i.projectId, p.id))
|
|
211
|
+
.select(({ i }) => ({ id: i.id, title: i.title })),
|
|
212
|
+
})),
|
|
213
|
+
)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Child component subscribes to the child Collection
|
|
217
|
+
@Component({
|
|
218
|
+
selector: 'app-issue-list',
|
|
219
|
+
standalone: true,
|
|
220
|
+
template: `
|
|
221
|
+
@for (issue of query.data(); track issue.id) {
|
|
222
|
+
<li>{{ issue.title }}</li>
|
|
223
|
+
}
|
|
224
|
+
`,
|
|
225
|
+
})
|
|
226
|
+
export class IssueListComponent {
|
|
227
|
+
issuesCollection = input.required<Collection>()
|
|
228
|
+
|
|
229
|
+
query = injectLiveQuery(this.issuesCollection())
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
With `toArray()`, child results are plain arrays and the parent re-emits on child changes:
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
import { toArray, eq } from '@tanstack/angular-db'
|
|
237
|
+
|
|
238
|
+
query = injectLiveQuery((q) =>
|
|
239
|
+
q.from({ p: projectsCollection }).select(({ p }) => ({
|
|
240
|
+
id: p.id,
|
|
241
|
+
name: p.name,
|
|
242
|
+
issues: toArray(
|
|
243
|
+
q
|
|
244
|
+
.from({ i: issuesCollection })
|
|
245
|
+
.where(({ i }) => eq(i.projectId, p.id))
|
|
246
|
+
.select(({ i }) => ({ id: i.id, title: i.title })),
|
|
247
|
+
),
|
|
248
|
+
})),
|
|
249
|
+
)
|
|
250
|
+
// project.issues is a plain array — no child component subscription needed
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
See db-core/live-queries/SKILL.md for full includes rules (correlation conditions, nested includes, aggregates).
|
|
254
|
+
|
|
185
255
|
## Common Mistakes
|
|
186
256
|
|
|
187
257
|
### CRITICAL Using injectLiveQuery outside injection context
|