Files
supabase/apps/temp-docs/docs/reference/dart/update.mdx
2022-04-26 14:17:19 +02:00

109 lines
1.8 KiB
Plaintext

---
id: update
title: "Modify data: update()"
slug: update
custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/dart.yml
---
import Tabs from '@theme/Tabs';
import TabsPanel from '@theme/TabsPanel';
Performs an UPDATE on the table.
<Tabs
defaultActiveId="dart"
groupId="reference/dart"
values={[{ label: 'Dart', value: 'dart' }]}>
<TabsPanel id="dart" label="dart">
```dart
final res = await supabase
.from('cities')
.update({ 'name': 'Middle Earth' })
.match({ 'name': 'Auckland' })
.execute();
```
</TabsPanel>
</Tabs>
## Notes
TODO update the link to dart
- `update()` should always be combined with [Filters](/docs/reference/javascript/using-filters) to target the item(s) you wish to update.
## Examples
### Updating your data
<Tabs
defaultActiveId="dart"
groupId="reference/dart"
values={[{ label: 'Dart', value: 'dart' }]}>
<TabsPanel id="dart" label="dart">
```dart
final res = await supabase
.from('cities')
.update({ 'name': 'Middle Earth' })
.match({ 'name': 'Auckland' })
.execute();
```
</TabsPanel>
</Tabs>
### Updating JSON data
Postgres offers a
[number of operators](https://www.postgresql.org/docs/current/functions-json.html)
for working with JSON data. Right now it is only possible to update an entire JSON document,
but we are [working on ideas](https://github.com/PostgREST/postgrest/issues/465) for updating individual keys.
<Tabs
defaultActiveId="dart"
groupId="reference/dart"
values={[{ label: 'Dart', value: 'dart' }]}>
<TabsPanel id="dart" label="dart">
```dart
final res = await supabase
.from('users')
.update({
'address': {
'street': 'Melrose Place',
'postcode': 90210
}
})
.eq('address->postcode', 90210)
.execute();
```
</TabsPanel>
</Tabs>