@tanstack/solid-db 0.2.9 → 0.2.11
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 +5 -4
- package/skills/solid-db/SKILL.md +172 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/solid-db",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.11",
|
|
4
4
|
"description": "Solid integration for @tanstack/db",
|
|
5
5
|
"author": "Kyle Mathews",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,17 +31,18 @@
|
|
|
31
31
|
"sideEffects": false,
|
|
32
32
|
"files": [
|
|
33
33
|
"dist",
|
|
34
|
-
"src"
|
|
34
|
+
"src",
|
|
35
|
+
"skills"
|
|
35
36
|
],
|
|
36
37
|
"dependencies": {
|
|
37
38
|
"@solid-primitives/map": "^0.7.2",
|
|
38
|
-
"@tanstack/db": "0.5.
|
|
39
|
+
"@tanstack/db": "0.5.31"
|
|
39
40
|
},
|
|
40
41
|
"peerDependencies": {
|
|
41
42
|
"solid-js": ">=1.9.0"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
|
-
"@electric-sql/client": "^1.5.
|
|
45
|
+
"@electric-sql/client": "^1.5.12",
|
|
45
46
|
"@solidjs/testing-library": "^0.8.10",
|
|
46
47
|
"@vitest/coverage-istanbul": "^3.2.4",
|
|
47
48
|
"jsdom": "^27.4.0",
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: solid-db
|
|
3
|
+
description: >
|
|
4
|
+
SolidJS bindings for TanStack DB. useLiveQuery returns an Accessor that
|
|
5
|
+
doubles as data access (call as function) with state/status properties.
|
|
6
|
+
Fine-grained reactivity: signal reads MUST happen inside the query function
|
|
7
|
+
for tracking. Config passed as Accessor (() => config). Built-in Suspense
|
|
8
|
+
support via createResource. ReactiveMap for state. Import from
|
|
9
|
+
@tanstack/solid-db (re-exports all of @tanstack/db).
|
|
10
|
+
type: framework
|
|
11
|
+
library: db
|
|
12
|
+
framework: solid
|
|
13
|
+
library_version: '0.5.30'
|
|
14
|
+
requires:
|
|
15
|
+
- db-core
|
|
16
|
+
sources:
|
|
17
|
+
- 'TanStack/db:docs/framework/solid/overview.md'
|
|
18
|
+
- 'TanStack/db:packages/solid-db/src/useLiveQuery.ts'
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
This skill builds on db-core. Read it first for collection setup, query builder, and mutation patterns.
|
|
22
|
+
|
|
23
|
+
# TanStack DB — SolidJS
|
|
24
|
+
|
|
25
|
+
## Setup
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { useLiveQuery, eq, not } from '@tanstack/solid-db'
|
|
29
|
+
import { For, Show, Suspense } from 'solid-js'
|
|
30
|
+
|
|
31
|
+
function TodoList() {
|
|
32
|
+
const todosQuery = useLiveQuery((q) =>
|
|
33
|
+
q
|
|
34
|
+
.from({ todo: todoCollection })
|
|
35
|
+
.where(({ todo }) => not(todo.completed))
|
|
36
|
+
.orderBy(({ todo }) => todo.created_at, 'asc'),
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Suspense fallback={<div>Loading...</div>}>
|
|
41
|
+
<ul>
|
|
42
|
+
<For each={todosQuery()}>{(todo) => <li>{todo.text}</li>}</For>
|
|
43
|
+
</ul>
|
|
44
|
+
</Suspense>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`@tanstack/solid-db` re-exports everything from `@tanstack/db`.
|
|
50
|
+
|
|
51
|
+
## Hook
|
|
52
|
+
|
|
53
|
+
### useLiveQuery
|
|
54
|
+
|
|
55
|
+
Returns an `Accessor<Array<T>>` with additional properties. Call it as a function to get data:
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
// Query function — call result as function for data
|
|
59
|
+
const query = useLiveQuery((q) => q.from({ todo: todoCollection }))
|
|
60
|
+
// query() → Array<T> (data)
|
|
61
|
+
// query.data → DEPRECATED — use query() instead. Migrate any existing code.
|
|
62
|
+
// query.status → CollectionStatus
|
|
63
|
+
// query.isLoading, query.isReady, query.isError
|
|
64
|
+
// query.state → ReactiveMap<TKey, T>
|
|
65
|
+
// query.collection → Collection
|
|
66
|
+
|
|
67
|
+
// With reactive signals — signals MUST be read INSIDE the query function
|
|
68
|
+
const [minPriority, setMinPriority] = createSignal(5)
|
|
69
|
+
const query = useLiveQuery((q) =>
|
|
70
|
+
q
|
|
71
|
+
.from({ todo: todoCollection })
|
|
72
|
+
.where(({ todo }) => gt(todo.priority, minPriority())),
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
// Config object — pass as Accessor
|
|
76
|
+
const query = useLiveQuery(() => ({
|
|
77
|
+
query: (q) => q.from({ todo: todoCollection }),
|
|
78
|
+
gcTime: 60000,
|
|
79
|
+
}))
|
|
80
|
+
|
|
81
|
+
// Pre-created collection — pass as Accessor
|
|
82
|
+
const query = useLiveQuery(() => preloadedCollection)
|
|
83
|
+
|
|
84
|
+
// Conditional query
|
|
85
|
+
const query = useLiveQuery((q) => {
|
|
86
|
+
const id = userId()
|
|
87
|
+
if (!id) return undefined
|
|
88
|
+
return q
|
|
89
|
+
.from({ todo: todoCollection })
|
|
90
|
+
.where(({ todo }) => eq(todo.userId, id))
|
|
91
|
+
})
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Solid-Specific Patterns
|
|
95
|
+
|
|
96
|
+
### Signal reads inside query function
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
// CORRECT — signal read tracked inside query function
|
|
100
|
+
const [category, setCategory] = createSignal('work')
|
|
101
|
+
const query = useLiveQuery((q) =>
|
|
102
|
+
q
|
|
103
|
+
.from({ todo: todoCollection })
|
|
104
|
+
.where(({ todo }) => eq(todo.category, category())),
|
|
105
|
+
)
|
|
106
|
+
// Query re-runs when category() changes
|
|
107
|
+
|
|
108
|
+
// WRONG — signal read outside, not tracked
|
|
109
|
+
const cat = category() // read here loses tracking
|
|
110
|
+
const query = useLiveQuery((q) =>
|
|
111
|
+
q.from({ todo: todoCollection }).where(({ todo }) => eq(todo.category, cat)),
|
|
112
|
+
)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Suspense integration
|
|
116
|
+
|
|
117
|
+
```tsx
|
|
118
|
+
<Suspense fallback={<div>Loading...</div>}>
|
|
119
|
+
<For each={todosQuery()}>{(todo) => <li>{todo.text}</li>}</For>
|
|
120
|
+
</Suspense>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`useLiveQuery` integrates with Solid's `createResource` — wrap in `<Suspense>` for loading states.
|
|
124
|
+
|
|
125
|
+
## Common Mistakes
|
|
126
|
+
|
|
127
|
+
### HIGH Reading signals outside the query function
|
|
128
|
+
|
|
129
|
+
Wrong:
|
|
130
|
+
|
|
131
|
+
```tsx
|
|
132
|
+
const [userId] = createSignal(1)
|
|
133
|
+
const id = userId()
|
|
134
|
+
const query = useLiveQuery((q) =>
|
|
135
|
+
q.from({ todo: todoCollection }).where(({ todo }) => eq(todo.userId, id)),
|
|
136
|
+
)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Correct:
|
|
140
|
+
|
|
141
|
+
```tsx
|
|
142
|
+
const [userId] = createSignal(1)
|
|
143
|
+
const query = useLiveQuery((q) =>
|
|
144
|
+
q
|
|
145
|
+
.from({ todo: todoCollection })
|
|
146
|
+
.where(({ todo }) => eq(todo.userId, userId())),
|
|
147
|
+
)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Solid's reactivity tracks signal reads inside reactive contexts. Reading outside the query function captures the value at creation time — changes won't trigger re-execution.
|
|
151
|
+
|
|
152
|
+
Source: docs/framework/solid/overview.md
|
|
153
|
+
|
|
154
|
+
### MEDIUM Using deprecated query.data instead of query()
|
|
155
|
+
|
|
156
|
+
Wrong:
|
|
157
|
+
|
|
158
|
+
```tsx
|
|
159
|
+
<For each={todosQuery.data}>{(todo) => <li>{todo.text}</li>}</For>
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Correct:
|
|
163
|
+
|
|
164
|
+
```tsx
|
|
165
|
+
<For each={todosQuery()}>{(todo) => <li>{todo.text}</li>}</For>
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
`query.data` is deprecated. Always use `query()` to access data. If you encounter existing code using `.data`, migrate it to the function call form.
|
|
169
|
+
|
|
170
|
+
See also: db-core/live-queries/SKILL.md — for query builder API.
|
|
171
|
+
|
|
172
|
+
See also: db-core/mutations-optimistic/SKILL.md — for mutation patterns.
|