mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
115 lines
1.9 KiB
Plaintext
115 lines
1.9 KiB
Plaintext
---
|
|
id: patch
|
|
title: 'Updating'
|
|
description: 'How to update records in your database with Supabase'
|
|
---
|
|
|
|
|
|
import DummyData from '../common/DummyData.mdx'
|
|
import Collapsable from '../../src/components/Collapsable'
|
|
import CommonResponses from '../common/CommonResponses.mdx'
|
|
import CommonFilters from '../common/CommonFilters'
|
|
import FromFunction from '../common/FromFunction.mdx'
|
|
|
|
<DummyData />
|
|
|
|
### Update record
|
|
|
|
This example how to update a country:
|
|
|
|
<!-- prettier-ignore -->
|
|
```js {7-10}
|
|
import { createClient } from '@supabase/supabase-js'
|
|
|
|
const supabase = createClient('https://world.supabase.co', '1a2b-3c4d-5e6f-7g8h')
|
|
|
|
const updateCountryName = async () => {
|
|
try {
|
|
let updates = await supabase
|
|
.from('countries')
|
|
.udpate({ name: 'Middle Earth' })
|
|
.match({ name: 'New Zealand' })
|
|
|
|
return updates
|
|
} catch (error) {
|
|
console.log('Error: ', error)
|
|
}
|
|
}
|
|
```
|
|
|
|
<Collapsable title="Toggle Example Response">
|
|
|
|
@todo
|
|
|
|
</Collapsable>
|
|
|
|
|
|
## Reference
|
|
|
|
### `from()`
|
|
<FromFunction verb='patch' />
|
|
|
|
### `update()`
|
|
```js {3}
|
|
supabase
|
|
.from(tableName)
|
|
.udpate(data, options?)
|
|
```
|
|
|
|
#### `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
|
|
|
|
### `filter()`
|
|
<CommonFilters filter='filter'/>
|
|
|
|
### `match()`
|
|
<CommonFilters filter='match'/>
|
|
|
|
### `eq()`
|
|
<CommonFilters filter='eq'/>
|
|
|
|
### `gt()`
|
|
<CommonFilters filter='gt'/>
|
|
|
|
### `lt()`
|
|
<CommonFilters filter='lt'/>
|
|
|
|
### `gte()`
|
|
<CommonFilters filter='gte'/>
|
|
|
|
### `lte()`
|
|
<CommonFilters filter='lte'/>
|
|
|
|
### `like()`
|
|
<CommonFilters filter='like'/>
|
|
|
|
### `ilike()`
|
|
<CommonFilters filter='ilike'/>
|
|
|
|
### `is()`
|
|
<CommonFilters filter='is'/>
|
|
|
|
### `in()`
|
|
<CommonFilters filter='in'/>
|
|
|
|
### `not()`
|
|
<CommonFilters filter='not'/>
|
|
|
|
## Responses
|
|
|
|
#### 200 OK
|
|
Successful
|
|
|
|
<CommonResponses /> |