mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
85 lines
1.4 KiB
Plaintext
85 lines
1.4 KiB
Plaintext
---
|
|
id: patch
|
|
title: 'Updating'
|
|
---
|
|
|
|
|
|
import DummyData from '../common/DummyData.mdx'
|
|
import Collapsable from '../../src/components/Collapsable'
|
|
import CommonResponses from '../common/CommonResponses.mdx'
|
|
import CommonFilters from '../common/CommonFilters.mdx'
|
|
|
|
|
|
We will be using these tables as reference for our examples:
|
|
|
|
<DummyData />
|
|
|
|
|
|
|
|
### Update record
|
|
|
|
This example how to update a country:
|
|
|
|
<!-- prettier-ignore -->
|
|
```js {8}
|
|
import { createClient } from '@supabase/supabase-js'
|
|
|
|
const supabase = createClient('https://world.supabase.io', '1a2b-3c4d-5e6f-7g8h')
|
|
|
|
const updateCountryName = async () => {
|
|
try {
|
|
let updates = await supabase
|
|
.patch('countries', { name: 'Middle Earth' })
|
|
.match({ name: 'New Zealand' })
|
|
|
|
return updates
|
|
} catch (error) {
|
|
console.log('Error: ', error)
|
|
}
|
|
}
|
|
```
|
|
|
|
<Collapsable title="Toggle Example Response">
|
|
|
|
@todo
|
|
|
|
</Collapsable>
|
|
|
|
|
|
## Reference
|
|
|
|
|
|
### `patch()`
|
|
```js
|
|
supabase
|
|
.patch(tableName, data, options?)
|
|
```
|
|
|
|
##### tableName `:string`
|
|
Name of table in the database where data will be saved.
|
|
|
|
##### data `:object`
|
|
New record values.
|
|
|
|
|
|
##### options `:object?`
|
|
|
|
```js
|
|
const options = {
|
|
bulk: false // Protects against bulk updates. Set to true if you intend to perform a bulk change.
|
|
}
|
|
```
|
|
|
|
----
|
|
|
|
|
|
## Filtering
|
|
|
|
<CommonFilters verb="patch" />
|
|
|
|
## Responses
|
|
|
|
#### 200 OK
|
|
Successful
|
|
|
|
<CommonResponses /> |