File tree Expand file tree Collapse file tree 1 file changed +5
-20
lines changed
client-sdk-references/javascript-web/javascript-orm Expand file tree Collapse file tree 1 file changed +5
-20
lines changed Original file line number Diff line number Diff line change @@ -165,31 +165,16 @@ Below are examples comparing Drizzle and PowerSync syntax for common database op
165165
166166### Watched Queries
167167
168+ For watched queries with Drizzle it's recommended to use the ` watch() ` function from the Drizzle integration which takes in a Drizzle query.
169+
168170<CodeGroup >
169171 ``` js Drizzle
170- import { toCompilableQuery } from " @powersync/drizzle-driver" ;
171-
172- // `compile()` is automatically called internally in the hooks, but not for `watch()`
173- const compiledQuery = toCompilableQuery (db .select ().from (users)).compile ();
174-
175- powerSyncDb .watch (compiledQuery .sql , compiledQuery .parameters , {
176- onResult (results ) {
177- console .log (results .rows ? ._array );
178- },
179- });
180-
181- // [{ id: '1', name: 'John' }]
182- ` ` `
183-
184- ` ` ` ts Drizzle (TS )
185- import { toCompilableQuery } from " @powersync/drizzle-driver" ;
186172
187- // `compile()` is automatically called internally in the hooks, but not for `watch()`
188- const compiledQuery = toCompilableQuery (db .select ().from (users)).compile ();
173+ const query = db .select ().from (users);
189174
190- powerSyncDb .watch (compiledQuery . sql , compiledQuery . parameters as [] , {
175+ db .watch (query , {
191176 onResult (results ) {
192- console .log (( results . rows ? . _array as ( typeof users . $inferSelect )[]) );
177+ console .log (results);
193178 },
194179 });
195180
You can’t perform that action at this time.
0 commit comments