Skip to content

Commit 4a8f78e

Browse files
docs(tanstack-react-query): document Drizzle ORM support (#623)
Co-authored-by: Christiaan Landman <[email protected]>
1 parent 8894360 commit 4a8f78e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

packages/tanstack-react-query/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,42 @@ export const TodoListDisplay = () => {
158158
);
159159
};
160160
```
161+
162+
### Drizzle Support
163+
164+
[Drizzle queries](https://github.com/powersync-ja/powersync-js/tree/main/packages/drizzle-driver) can be used with the `useQuery` and `useSuspenseQuery` hooks by converting them to a compilable query using the `toCompilableQuery` utility from `@powersync/drizzle-driver`.
165+
166+
```TSX
167+
// TodoListDisplay.tsx
168+
import { useQuery } from '@powersync/tanstack-react-query';
169+
import { toCompilableQuery } from '@powersync/drizzle-driver';
170+
171+
export const TodoListDisplay = () => {
172+
const drizzleQuery = drizzleDb.select().from(lists);
173+
174+
const { data: todoLists, isLoading, error } = useQuery({
175+
queryKey: ['todoLists'],
176+
query: toCompilableQuery(drizzleQuery), // The type of the rows in `data` are inferred from the Drizzle query
177+
});
178+
179+
if (isLoading) {
180+
return <div>Loading todo lists...</div>;
181+
}
182+
183+
if (error) {
184+
return <div>Error loading todo lists: {error.message}</div>;
185+
}
186+
187+
return (
188+
<ul>
189+
{todoLists?.map((list) => (
190+
<li key={list.id}>{list.name}</li>
191+
))}
192+
</ul>
193+
);
194+
};
195+
```
196+
197+
The `toCompilableQuery` function wraps your Drizzle query to make it compatible with useQuery and useSuspenseQuery.
198+
199+
For more information on using Drizzle with PowerSync, see the [Drizzle Driver documentation](https://github.com/powersync-ja/powersync-js/tree/main/packages/drizzle-driver).

0 commit comments

Comments
 (0)