mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
The following were done: - Complete delete.mdx and patch.mdx. - (Boyscout) Change one sentence in about.md. - Reroute internal links due to the restructuring of the library section in the previous commit.
122 lines
2.7 KiB
Plaintext
122 lines
2.7 KiB
Plaintext
---
|
|
id: patch
|
|
title: 'Update Rows'
|
|
---
|
|
|
|
import Tabs from '@theme/Tabs';
|
|
import TabItem from '@theme/TabItem';
|
|
|
|
We will be using these tables as reference for our examples:
|
|
```json
|
|
{
|
|
"companies": [
|
|
{ "Id": 1, "name": "Pied Piper", "employeeCount": 10 },
|
|
{ "Id": 2, "name": "Hooli", "employeeCount": 1000 },
|
|
{ "Id": 3, "name": "Yao Net", "employeeCount": 100 },
|
|
{ "Id": 4, "name": "See Food App", "employeeCount": null }
|
|
],
|
|
}
|
|
```
|
|
|
|
<Tabs
|
|
defaultValue="nodeJs"
|
|
values={[
|
|
{ label: 'Node.js', value: 'nodeJs', },
|
|
{ label: 'Python', value: 'py', },
|
|
]
|
|
}>
|
|
<TabItem value="nodeJs">
|
|
|
|
```js
|
|
supabase.patch(tableName, data, options?)
|
|
|
|
```
|
|
Given the `options?` set (if any), this **asynchronously** and partially updates all rows from the specified `tableName` in your database
|
|
with the specified `data`.
|
|
</TabItem>
|
|
|
|
<TabItem value="py">
|
|
|
|
```py
|
|
# TODO
|
|
```
|
|
</TabItem>
|
|
</Tabs>
|
|
|
|
<Tabs
|
|
defaultValue="nodeJs"
|
|
values={[
|
|
{ label: 'Node.js', value: 'nodeJs', },
|
|
{ label: 'Python', value: 'py', },
|
|
]
|
|
}>
|
|
<TabItem value="nodeJs">
|
|
|
|
```js
|
|
supabase.put(tableName, data, options?)
|
|
|
|
```
|
|
Given the `options?` set (if any), this **asynchronously** and fully replaces all rows from the specified `tableName` in your database
|
|
with the specified `data`.
|
|
</TabItem>
|
|
|
|
<TabItem value="py">
|
|
|
|
```py
|
|
# TODO
|
|
```
|
|
</TabItem>
|
|
</Tabs>
|
|
|
|
## Method arguments
|
|
Arguments for both types of update are the same.
|
|
### tableName
|
|
`required` string
|
|
Name of table in the database that will be updated.
|
|
|
|
### data
|
|
`required` array
|
|
Array of rows of type `object` which contain information to be updated into the selected table.
|
|
|
|
|
|
### options
|
|
`optional` object
|
|
All available options and examples it their usage can be found [here](../library/options).
|
|
|
|
## Additional filtering
|
|
To specifically indicate which resources are to be updated, additional filters can be used.
|
|
They can be found [here](../library/filters).
|
|
|
|
## Example
|
|
|
|
### Mass update
|
|
Updating employeeCount for all companies.
|
|
```js
|
|
supabase.patch("companies", { employeeCount: 50 })
|
|
```
|
|
|
|
The following will be returned with the status code `200 OK`:
|
|
```json
|
|
[
|
|
{ "Id": 1, "name": "Pied Piper", "employeeCount": 50 },
|
|
{ "Id": 2, "name": "Hooli", "employeeCount": 50 },
|
|
{ "Id": 3, "name": "Yao Net", "employeeCount": 50 },
|
|
{ "Id": 4, "name": "See Food App", "employeeCount": 50 }
|
|
]
|
|
```
|
|
|
|
### Using filters
|
|
Updating employeeCount for companies where its columnName "name" is equal to "See Food App".
|
|
```js
|
|
supabase.patch("companies", { employeeCount: 50 }).eq("name", "See Food App")
|
|
```
|
|
|
|
The following will be returned with the status code `200 OK`:
|
|
```json
|
|
[
|
|
{ "Id": 4, "name": "See Food App", "employeeCount": 50 }
|
|
]
|
|
```
|
|
|
|
## Responses
|
|
Aside from the status code `200 OK`, other common responses can be found [here](../library/responses). |