Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 5 additions & 20 deletions client-sdk-references/javascript-web/javascript-orm/drizzle.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -165,31 +165,16 @@ Below are examples comparing Drizzle and PowerSync syntax for common database op

### Watched Queries

For watched queries with Drizzle it's recommended to use the `watch()` function from the Drizzle integration which takes in a Drizzle query.

<CodeGroup>
```js Drizzle
import { toCompilableQuery } from "@powersync/drizzle-driver";

// `compile()` is automatically called internally in the hooks, but not for `watch()`
const compiledQuery = toCompilableQuery(db.select().from(users)).compile();

powerSyncDb.watch(compiledQuery.sql, compiledQuery.parameters, {
onResult(results) {
console.log(results.rows?._array);
},
});

// [{ id: '1', name: 'John' }]
```

```ts Drizzle (TS)
import { toCompilableQuery } from "@powersync/drizzle-driver";

// `compile()` is automatically called internally in the hooks, but not for `watch()`
const compiledQuery = toCompilableQuery(db.select().from(users)).compile();
const query = db.select().from(users);

powerSyncDb.watch(compiledQuery.sql, compiledQuery.parameters as [], {
db.watch(query, {
onResult(results) {
console.log((results.rows?._array as (typeof users.$inferSelect)[]));
console.log(results);
},
});

Expand Down