-
Notifications
You must be signed in to change notification settings - Fork 250
Add framework DB adapter package #1699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jherr
wants to merge
4
commits into
main
Choose a base branch
from
feat/framework-db-adapter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2d4ab7b
feat: add framework DB adapter package
jherr 2235dfe
ci: apply automated fixes
autofix-ci[bot] f2d1096
fix(octane-db): address CodeRabbit review on #1699
jherr f212053
docs(octane): demonstrate pagination in useLiveInfiniteQuery example
jherr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@tanstack/octane-db': minor | ||
| --- | ||
|
|
||
| Add `@tanstack/octane-db`, an Octane framework adapter for TanStack DB with full hook parity to `@tanstack/react-db` and Octane compiler hook-slot forwarding. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| --- | ||
| title: TanStack DB Octane Adapter | ||
| id: adapter | ||
| --- | ||
|
|
||
| ## Installation | ||
|
|
||
| ```sh | ||
| npm install @tanstack/octane-db octane @octanejs/vite-plugin | ||
| ``` | ||
|
|
||
| Configure the Octane compiler in your Vite app — see [Octane build tools](https://octanejs.dev/docs/build-tools). | ||
|
|
||
| `@tanstack/octane-db` re-exports everything from `@tanstack/db`. Import collections, query helpers, and hooks from `@tanstack/octane-db`. | ||
|
|
||
| ## Octane Hooks | ||
|
|
||
| See the [Octane Functions Reference](./reference/index.md) for the full hook list. | ||
|
|
||
| For comprehensive documentation on writing queries (filtering, joins, aggregations, etc.), see the [Live Queries Guide](../../guides/live-queries). | ||
|
|
||
| ## Basic Usage | ||
|
|
||
| The examples below assume `todosCollection` and `postsCollection` are collections you've already created (see the [Collections guide](../../guides/collections)), and that query helpers such as `eq` and `gt` are imported from `@tanstack/octane-db`. | ||
|
|
||
| ### useLiveQuery | ||
|
|
||
| ```tsx | ||
| import { useLiveQuery, eq } from '@tanstack/octane-db' | ||
|
|
||
| function TodoList() { | ||
| const { data, isLoading } = useLiveQuery((q) => | ||
| q.from({ todos: todosCollection }) | ||
| .where(({ todos }) => eq(todos.completed, false)) | ||
| .select(({ todos }) => ({ id: todos.id, text: todos.text })) | ||
| ) | ||
|
|
||
| if (isLoading) return <div>Loading...</div> | ||
|
|
||
| return ( | ||
| <ul> | ||
| {data.map(todo => <li key={todo.id}>{todo.text}</li>)} | ||
| </ul> | ||
| ) | ||
| } | ||
| ``` | ||
|
|
||
| ### Dependency Arrays | ||
|
|
||
| All query hooks (`useLiveQuery`, `useLiveInfiniteQuery`, `useLiveSuspenseQuery`) accept an optional dependency array as their last parameter. When any value in the array changes, the query is recreated and re-executed. | ||
|
|
||
| ```tsx | ||
| function FilteredTodos({ minPriority }: { minPriority: number }) { | ||
| const { data } = useLiveQuery( | ||
| (q) => q.from({ todos: todosCollection }) | ||
| .where(({ todos }) => gt(todos.priority, minPriority)), | ||
| [minPriority] | ||
| ) | ||
|
|
||
| return <div>{data.length} high-priority todos</div> | ||
| } | ||
| ``` | ||
|
|
||
| ### useLiveInfiniteQuery | ||
|
|
||
| ```tsx | ||
| import { useLiveInfiniteQuery, eq } from '@tanstack/octane-db' | ||
|
|
||
| function PostFeed({ category }: { category: string }) { | ||
| const { data, fetchNextPage, hasNextPage } = useLiveInfiniteQuery( | ||
| (q) => q | ||
| .from({ posts: postsCollection }) | ||
| .where(({ posts }) => eq(posts.category, category)) | ||
| .orderBy(({ posts }) => posts.createdAt, 'desc'), | ||
| { | ||
| pageSize: 20, | ||
| getNextPageParam: (lastPage, allPages) => | ||
| lastPage.length === 20 ? allPages.length : undefined | ||
| }, | ||
| [category] | ||
| ) | ||
|
|
||
| return ( | ||
| <div> | ||
| <ul> | ||
| {data.map(post => <li key={post.id}>{post.title}</li>)} | ||
| </ul> | ||
| {hasNextPage && ( | ||
| <button onClick={() => fetchNextPage()}>Load more</button> | ||
| )} | ||
| </div> | ||
| ) | ||
| } | ||
| ``` | ||
|
|
||
| ### useLiveSuspenseQuery | ||
|
|
||
| Wrap components in Octane `Suspense` (and `@try` / `@catch` or an error boundary for failures): | ||
|
|
||
| ```tsx | ||
| import { Suspense } from 'octane' | ||
| import { useLiveSuspenseQuery, eq } from '@tanstack/octane-db' | ||
|
|
||
| function TodoList({ filter }: { filter: string }) { | ||
| const { data } = useLiveSuspenseQuery( | ||
| (q) => q.from({ todos: todosCollection }) | ||
| .where(({ todos }) => eq(todos.filter, filter)), | ||
| [filter] | ||
| ) | ||
|
|
||
| return ( | ||
| <ul> | ||
| {data.map(todo => <li key={todo.id}>{todo.text}</li>)} | ||
| </ul> | ||
| ) | ||
| } | ||
|
|
||
| function App() { | ||
| return ( | ||
| <Suspense fallback={<div>Loading...</div>}> | ||
| <TodoList filter="active" /> | ||
| </Suspense> | ||
| ) | ||
| } | ||
| ``` | ||
|
|
||
| ### Incremental adoption from React | ||
|
|
||
| You can host compiled Octane components inside an existing React 19 app with `OctaneCompat` from `octane/react`. Islands can use `@tanstack/octane-db` hooks while the rest of the app keeps `@tanstack/react-db`. See [OctaneCompat](https://octanejs.dev/docs/differences-from-react). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Octane Functions Reference | ||
|
|
||
| Generated API reference for `@tanstack/octane-db`. Run `pnpm generate-docs` at the repo root to refresh these pages. | ||
|
|
||
| - [useLiveQuery](./functions/useLiveQuery.md) | ||
| - [useLiveSuspenseQuery](./functions/useLiveSuspenseQuery.md) | ||
| - [useLiveInfiniteQuery](./functions/useLiveInfiniteQuery.md) | ||
| - [usePacedMutations](./functions/usePacedMutations.md) | ||
| - [useLiveQueryEffect](./functions/useLiveQueryEffect.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # @tanstack/octane-db | ||
|
|
||
| ## 0.0.1 | ||
|
|
||
| Initial release of the Octane framework adapter for TanStack DB. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # @tanstack/octane-db | ||
|
|
||
| Octane hooks for TanStack DB. See [TanStack/db](https://github.com/TanStack/db) for more details. | ||
|
|
||
| Install `octane` alongside this package and configure the Octane compiler in your build tool (see [octanejs.dev](https://octanejs.dev/docs/build-tools)). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| { | ||
| "name": "@tanstack/octane-db", | ||
| "version": "0.0.1", | ||
| "description": "Octane integration for @tanstack/db", | ||
| "author": "Kyle Mathews", | ||
| "license": "MIT", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/TanStack/db.git", | ||
| "directory": "packages/octane-db" | ||
| }, | ||
| "homepage": "https://tanstack.com/db", | ||
| "keywords": [ | ||
| "optimistic", | ||
| "octane", | ||
| "typescript", | ||
| "tanstack-intent" | ||
| ], | ||
| "octane": { | ||
| "hookSlots": { | ||
| "manual": [ | ||
| "src" | ||
| ] | ||
| } | ||
| }, | ||
| "scripts": { | ||
| "build": "vite build", | ||
| "build:minified": "vite build --minify", | ||
| "dev": "vite build --watch", | ||
| "test": "vitest --run", | ||
| "lint": "eslint . --fix" | ||
| }, | ||
| "type": "module", | ||
| "main": "dist/cjs/index.cjs", | ||
| "module": "dist/esm/index.js", | ||
| "types": "dist/esm/index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "import": { | ||
| "types": "./dist/esm/index.d.ts", | ||
| "default": "./dist/esm/index.js" | ||
| }, | ||
| "require": { | ||
| "types": "./dist/cjs/index.d.cts", | ||
| "default": "./dist/cjs/index.cjs" | ||
| } | ||
| }, | ||
| "./package.json": "./package.json" | ||
| }, | ||
| "sideEffects": false, | ||
| "files": [ | ||
| "dist", | ||
| "src", | ||
| "skills" | ||
| ], | ||
| "dependencies": { | ||
| "@tanstack/db": "workspace:*" | ||
| }, | ||
| "peerDependencies": { | ||
| "octane": ">=0.1.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@electric-sql/client": "^1.5.15", | ||
| "@octanejs/testing-library": "^0.1.10", | ||
| "@octanejs/vite-plugin": "^0.1.13", | ||
| "@vitest/coverage-istanbul": "^3.2.4", | ||
| "octane": "^0.1.13", | ||
| "vitest": "^3.2.4" | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.