Skip to content

Commit 8e23322

Browse files
KyleAMathewsclaude
andauthored
Move collections to own packages (#252)
Co-authored-by: Claude <[email protected]>
1 parent baff162 commit 8e23322

36 files changed

+316
-408
lines changed

.changeset/chubby-turkeys-sell.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
"@tanstack/db-electric-collection": patch
3+
"@tanstack/db-query-collection": patch
4+
"@tanstack/db-example-react-todo": patch
5+
"@tanstack/db": patch
6+
---
7+
8+
Move Collections to their own packages
9+
10+
- Move local-only and local-storage collections to main `@tanstack/db` package
11+
- Create new `@tanstack/electric-db-collection` package for Electric SQL integration
12+
- Create new `@tanstack/query-db-collection` package for TanStack Query integration
13+
- Delete `@tanstack/db-collections` package (removed from repo)
14+
- Update example app and documentation to use new package structure
15+
16+
Why?
17+
18+
- Better separation of concerns
19+
- Independent versioning for each collection type
20+
- Cleaner dependencies (electric collections don't need query deps, etc.)
21+
- Easier to add more collection types moving forward

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,18 @@ TanStack DB is **backend agnostic** and **incrementally adoptable**:
4848
Sync data into collections:
4949

5050
```ts
51-
import { createQueryCollection } from "@tanstack/db-collections"
52-
53-
const todoCollection = createQueryCollection({
54-
queryKey: ["todos"],
55-
queryFn: async () => fetch("/api/todos"),
56-
getKey: (item) => item.id,
57-
schema: todoSchema, // any standard schema
58-
})
51+
import { createCollection, QueryClient } from "@tanstack/react-db"
52+
import { queryCollectionOptions } from "@tanstack/query-db-collection"
53+
54+
const todoCollection = createCollection(
55+
queryCollectionOptions({
56+
queryKey: ["todos"],
57+
queryFn: async () => fetch("/api/todos"),
58+
queryClient: new QueryClient(),
59+
getKey: (item) => item.id,
60+
schema: todoSchema, // any standard schema
61+
})
62+
)
5963
```
6064

6165
Use live queries in your components:
@@ -135,7 +139,9 @@ There's also an example [React todo app](./examples/react/todo) and usage exampl
135139
## 🔧 Install
136140

137141
```bash
138-
npm install @tanstack/react-db @tanstack/db-collections
142+
npm install @tanstack/react-db
143+
# Optional: for specific collection types
144+
npm install @tanstack/electric-db-collection @tanstack/query-db-collection
139145
```
140146

141147
Other framework integrations are in progress.

examples/react/todo/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
"private": true,
44
"version": "0.0.26",
55
"dependencies": {
6-
"@tanstack/db-collections": "^0.0.24",
7-
"@tanstack/query-core": "^5.81.5",
6+
"@tanstack/electric-db-collection": "^0.0.2",
7+
"@tanstack/query-core": "^5.75.7",
8+
"@tanstack/query-db-collection": "^0.0.2",
89
"@tanstack/react-db": "^0.0.19",
910
"@tanstack/react-router": "^1.125.6",
1011
"@tanstack/react-start": "^1.126.1",

examples/react/todo/src/api/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
validateUpdateTodo,
99
} from "../db/validation"
1010
import type { Express } from "express"
11-
import type { Txid } from "@tanstack/db-collections"
11+
import type { Txid } from "@tanstack/electric-db-collection"
1212

1313
// Create Express app
1414
const app: Express = express()

examples/react/todo/src/lib/collections.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { createCollection } from "@tanstack/react-db"
2-
import {
3-
electricCollectionOptions,
4-
queryCollectionOptions,
5-
} from "@tanstack/db-collections"
2+
import { electricCollectionOptions } from "@tanstack/electric-db-collection"
3+
import { queryCollectionOptions } from "@tanstack/query-db-collection"
64
import { QueryClient } from "@tanstack/query-core"
75
import { selectConfigSchema, selectTodoSchema } from "../db/validation"
86
import { api } from "./api"

examples/react/todo/src/routes/api/config.$id.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createServerFileRoute } from "@tanstack/react-start/server"
22
import { json } from "@tanstack/react-start"
33
import { sql } from "../../db/postgres"
44
import { validateUpdateConfig } from "../../db/validation"
5-
import type { Txid } from "@tanstack/db-collections"
5+
import type { Txid } from "@tanstack/electric-db-collection"
66

77
// Generate a transaction ID
88
async function generateTxId(tx: any): Promise<Txid> {

examples/react/todo/src/routes/api/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createServerFileRoute } from "@tanstack/react-start/server"
22
import { json } from "@tanstack/react-start"
33
import { sql } from "../../db/postgres"
44
import { validateInsertConfig } from "../../db/validation"
5-
import type { Txid } from "@tanstack/db-collections"
5+
import type { Txid } from "@tanstack/electric-db-collection"
66

77
// Generate a transaction ID
88
async function generateTxId(tx: any): Promise<Txid> {

examples/react/todo/src/routes/api/todos.$id.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createServerFileRoute } from "@tanstack/react-start/server"
22
import { json } from "@tanstack/react-start"
33
import { sql } from "../../db/postgres"
44
import { validateUpdateTodo } from "../../db/validation"
5-
import type { Txid } from "@tanstack/db-collections"
5+
import type { Txid } from "@tanstack/electric-db-collection"
66

77
// Generate a transaction ID
88
async function generateTxId(tx: any): Promise<Txid> {

examples/react/todo/src/routes/api/todos.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createServerFileRoute } from "@tanstack/react-start/server"
22
import { json } from "@tanstack/react-start"
33
import { sql } from "../../db/postgres"
44
import { validateInsertTodo } from "../../db/validation"
5-
import type { Txid } from "@tanstack/db-collections"
5+
import type { Txid } from "@tanstack/electric-db-collection"
66

77
// Generate a transaction ID
88
async function generateTxId(tx: any): Promise<Txid> {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@tanstack/db-monorepo",
33
"private": true,
4-
"description": "Optimistic UI library for sync engines",
4+
"description": "Reactive client queryable store for sync-first applications",
55
"version": "0.0.0",
66
"repository": {
77
"type": "git",

0 commit comments

Comments
 (0)