Skip to content

Commit de99f5a

Browse files
committed
Added ts example for drizzle watched queries.
1 parent f99788e commit de99f5a

File tree

1 file changed

+14
-2
lines changed
  • client-sdk-references/javascript-web/javascript-orm

1 file changed

+14
-2
lines changed

client-sdk-references/javascript-web/javascript-orm/drizzle.mdx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,21 @@ Below are examples comparing Drizzle and PowerSync syntax for common database op
175175
powerSyncDb.watch(compiledQuery.sql, compiledQuery.parameters, {
176176
onResult(results) {
177177
console.log(results.rows?._array);
178+
},
179+
});
180+
181+
// [{ id: '1', name: 'John' }]
182+
```
178183
179-
// With Typescript typing
180-
// console.log((results.rows?._array as (typeof users.$inferSelect)[]));
184+
```ts Drizzle (TS)
185+
import { toCompilableQuery } from "@powersync/drizzle-driver";
186+
187+
// `compile()` is automatically called internally in the hooks, but not for `watch()`
188+
const compiledQuery = toCompilableQuery(db.select().from(users)).compile();
189+
190+
powerSyncDb.watch(compiledQuery.sql, compiledQuery.parameters as [], {
191+
onResult(results) {
192+
console.log((results.rows?._array as (typeof users.$inferSelect)[]));
181193
},
182194
});
183195

0 commit comments

Comments
 (0)