@tanstack/vue-db 0.0.107 → 0.0.109

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/vue-db",
3
- "version": "0.0.107",
3
+ "version": "0.0.109",
4
4
  "description": "Vue integration for @tanstack/db",
5
5
  "author": "Kyle Mathews",
6
6
  "license": "MIT",
@@ -35,16 +35,17 @@
35
35
  "sideEffects": false,
36
36
  "files": [
37
37
  "dist",
38
- "src"
38
+ "src",
39
+ "skills"
39
40
  ],
40
41
  "dependencies": {
41
- "@tanstack/db": "0.5.30"
42
+ "@tanstack/db": "0.5.32"
42
43
  },
43
44
  "peerDependencies": {
44
45
  "vue": ">=3.3.0"
45
46
  },
46
47
  "devDependencies": {
47
- "@electric-sql/client": "^1.5.8",
48
+ "@electric-sql/client": "^1.5.12",
48
49
  "@vitejs/plugin-vue": "^6.0.4",
49
50
  "@vitest/coverage-istanbul": "^3.2.4",
50
51
  "vue": "^3.5.28"
@@ -0,0 +1,148 @@
1
+ ---
2
+ name: vue-db
3
+ description: >
4
+ Vue 3 bindings for TanStack DB. useLiveQuery composable with
5
+ MaybeRefOrGetter query functions, ComputedRef return values for all fields
6
+ (data, state, collection, status, isLoading, isReady, isError).
7
+ Dependency arrays with Vue refs. Conditional queries via returning
8
+ undefined/null. Pre-created collection support via ref or getter.
9
+ Import from @tanstack/vue-db (re-exports all of @tanstack/db).
10
+ type: framework
11
+ library: db
12
+ framework: vue
13
+ library_version: '0.5.30'
14
+ requires:
15
+ - db-core
16
+ sources:
17
+ - 'TanStack/db:docs/framework/vue/overview.md'
18
+ - 'TanStack/db:packages/vue-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 — Vue
24
+
25
+ ## Setup
26
+
27
+ ```vue
28
+ <script setup lang="ts">
29
+ import { useLiveQuery, eq, not } from '@tanstack/vue-db'
30
+
31
+ const { data: todos, isLoading } = useLiveQuery((q) =>
32
+ q
33
+ .from({ todo: todoCollection })
34
+ .where(({ todo }) => not(todo.completed))
35
+ .orderBy(({ todo }) => todo.created_at, 'asc'),
36
+ )
37
+ </script>
38
+
39
+ <template>
40
+ <div v-if="isLoading">Loading...</div>
41
+ <ul v-else>
42
+ <li v-for="todo in todos" :key="todo.id">{{ todo.text }}</li>
43
+ </ul>
44
+ </template>
45
+ ```
46
+
47
+ `@tanstack/vue-db` re-exports everything from `@tanstack/db`.
48
+
49
+ ## Hook
50
+
51
+ ### useLiveQuery
52
+
53
+ All return values are `ComputedRef`:
54
+
55
+ ```ts
56
+ // Query function with reactive deps
57
+ const minPriority = ref(5)
58
+ const { data, isLoading, isReady, status } = useLiveQuery(
59
+ (q) =>
60
+ q
61
+ .from({ todo: todoCollection })
62
+ .where(({ todo }) => gt(todo.priority, minPriority.value)),
63
+ [minPriority],
64
+ )
65
+
66
+ // Config object
67
+ const { data } = useLiveQuery({
68
+ query: (q) => q.from({ todo: todoCollection }),
69
+ gcTime: 60000,
70
+ })
71
+
72
+ // Pre-created collection (reactive via ref)
73
+ const { data } = useLiveQuery(preloadedCollection)
74
+
75
+ // Conditional query
76
+ const userId = ref<number | null>(null)
77
+ const { data, status } = useLiveQuery(
78
+ (q) => {
79
+ if (!userId.value) return undefined
80
+ return q
81
+ .from({ todo: todoCollection })
82
+ .where(({ todo }) => eq(todo.userId, userId.value))
83
+ },
84
+ [userId],
85
+ )
86
+ ```
87
+
88
+ ## Vue-Specific Patterns
89
+
90
+ ### Reactive dependencies with refs
91
+
92
+ ```ts
93
+ const filter = ref('active')
94
+ const { data } = useLiveQuery(
95
+ (q) =>
96
+ q
97
+ .from({ todo: todoCollection })
98
+ .where(({ todo }) => eq(todo.status, filter.value)),
99
+ [filter],
100
+ )
101
+ // Query re-runs when filter.value changes
102
+ ```
103
+
104
+ ### Mutations in event handlers
105
+
106
+ ```ts
107
+ const handleToggle = (id: number) => {
108
+ todoCollection.update(id, (draft) => {
109
+ draft.completed = !draft.completed
110
+ })
111
+ }
112
+ ```
113
+
114
+ ## Common Mistakes
115
+
116
+ ### CRITICAL Missing reactive deps in dependency array
117
+
118
+ Wrong:
119
+
120
+ ```ts
121
+ const userId = ref(1)
122
+ const { data } = useLiveQuery((q) =>
123
+ q
124
+ .from({ todo: todoCollection })
125
+ .where(({ todo }) => eq(todo.userId, userId.value)),
126
+ )
127
+ ```
128
+
129
+ Correct:
130
+
131
+ ```ts
132
+ const userId = ref(1)
133
+ const { data } = useLiveQuery(
134
+ (q) =>
135
+ q
136
+ .from({ todo: todoCollection })
137
+ .where(({ todo }) => eq(todo.userId, userId.value)),
138
+ [userId],
139
+ )
140
+ ```
141
+
142
+ Reactive refs used in the query must be included in the deps array for the query to re-run on changes.
143
+
144
+ Source: docs/framework/vue/overview.md
145
+
146
+ See also: db-core/live-queries/SKILL.md — for query builder API.
147
+
148
+ See also: db-core/mutations-optimistic/SKILL.md — for mutation patterns.