You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The PowerSync instance can be used with [React Query](https://tanstack.com/query/v3/docs/react/quick-start). The example below omits the necessary provider setup (see Quickstart).
276
300
277
301
```JSX
278
-
//ListWidget.jsx
302
+
//ListsWidget.jsx
279
303
import {useQuery} from'react-query';
304
+
import {FlatList, Text} from'react-native';
280
305
281
-
exportconstListWidget= () => {
306
+
exportconstListsWidget= () => {
282
307
const {data:lists} =useQuery({
283
308
queryKey:'lists',
284
309
queryFn:async () =>PowerSync.getAll('SELECT * from lists'),
// Watched queries should automatically reload after mutation
391
+
} catch (ex) {
392
+
Alert.alert('Error', ex.message)
393
+
}
394
+
}}
395
+
/>
396
+
</View>
397
+
)
398
+
}
399
+
```
400
+
401
+
### Transactions
402
+
403
+
Read and write transactions present a context where multiple changes can be made then finally committed to the DB or rolled back. This ensures that either all the changes get persisted, or no change is made to the DB (in the case of a rollback or exception).
404
+
405
+
`PowerSync.writeTransaction(callback)` automatically commits changes after the transaction callback is completed if `tx.rollback()` has not explicitly been called. If an exception is thrown in the callback then changes are automatically rolled back.
406
+
407
+
`PowerSync.readTransaction(callback)` automatically rolls back any attempted changes made in the transaction callback.
0 commit comments