Files
supabase/web/docs/library/patch.mdx
T

650 lines
11 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'
import CustomCodeBlock from '../../src/components/CustomCodeBlock'
import {
patchRecordJs,
patchFilterJs,
patchNotJs,
patchMatchJs,
patchEqJs,
patchNeqJs,
patchGtJs,
patchLtJs,
patchGteJs,
patchLteJs,
patchLikeJs,
patchIlikeJs,
patchIsJs,
patchInJs,
patchCsJs,
patchCdJs,
patchOvaJs,
patchOvrJs,
patchSlJs,
patchSrJs,
patchNxlJs,
patchNxrJs,
patchAdjJs,
} from './examples/patch'
<DummyData />
### Update record
<CustomCodeBlock
header="Updates information about a city."
js={patchRecordJs}
jsHighlight="{7-10}"
response={`{
"body": [
{ "name": "Middle Earth", "country_id": 554 },
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
## Reference
### `from()`
<FromFunction verb="patch" />
### `update()`
```js {3}
supabase
.from(tableName)
.update(data)
```
It is to note that it is required to apply filters when using `.update()`. Not using filters would result in an error.
#### `data: object`
New record values.
---
## Filtering
### `filter()`
<CustomCodeBlock
header="Shows how to use filter( ) with update( )"
js={patchFilterJs}
jsHighlight="{10}"
response={`{
"body": [
{ "name": "Mordor", "country_id": 250 },
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
<br />
<CommonFilters filter="filter" />
### `not()`
<CustomCodeBlock
header="Shows how to use not( ) with update( )"
js={patchNotJs}
jsHighlight="{10}"
response={`{
"body": [
{ "name": "Mordor", "country_id": 76 },
{ "name": "Mordor", "country_id": 156 },
{ "name": "Mordor", "country_id": 554 },
{ "name": "Mordor", "country_id": 556 },
{ "name": "Mordor", "country_id": 840 }
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
<br />
<CommonFilters filter="not" />
### `match()`
<CustomCodeBlock
header="Shows how to use match( ) with update( )"
js={patchMatchJs}
jsHighlight="{10}"
response={`{
"body": [
{ "name": "Mordor", "country_id": 156 },
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
<br />
<CommonFilters filter="match" />
### `eq()`
<CustomCodeBlock
header="Shows how to use eq( ) with update( )"
js={patchEqJs}
jsHighlight="{10}"
response={`{
"body": [
{ "name": "Mordor", "country_id": 840 },
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
<br />
<CommonFilters filter="eq" />
### `neq()`
<CustomCodeBlock
header="Shows how to use neq( ) with update( )"
js={patchNeqJs}
jsHighlight="{10}"
response={`{
"body": [
{ "name": "Mordor", "country_id": 76 },
{ "name": "Mordor", "country_id": 156 },
{ "name": "Mordor", "country_id": 250 },
{ "name": "Mordor", "country_id": 554 },
{ "name": "Mordor", "country_id": 556 },
{ "name": "Mordor", "country_id": 840 },
{ "name": "Mordor", "country_id": 840 }
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
<br />
<CommonFilters filter="neq" />
### `gt()`
<CustomCodeBlock
header="Shows how to use gt( ) with update( )"
js={patchGtJs}
jsHighlight="{10}"
response={`{
"body": [
{ "name": "Mordor", "country_id": 554 },
{ "name": "Mordor", "country_id": 556 },
{ "name": "Mordor", "country_id": 840 },
{ "name": "Mordor", "country_id": 840 }
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
<br />
<CommonFilters filter="gt" />
### `lt()`
<CustomCodeBlock
header="Shows how to use lt( ) with update( )"
js={patchLtJs}
jsHighlight="{10}"
response={`{
"body": [
{ "name": "Mordor", "country_id": 76 },
{ "name": "Mordor", "country_id": 156 }
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
<br />
<CommonFilters filter="lt" />
### `gte()`
<CustomCodeBlock
header="Shows how to use gte( ) with update( )"
js={patchGteJs}
jsHighlight="{10}"
response={`{
"body": [
{ "name": "Mordor", "country_id": 250 },
{ "name": "Mordor", "country_id": 554 },
{ "name": "Mordor", "country_id": 556 },
{ "name": "Mordor", "country_id": 840 },
{ "name": "Mordor", "country_id": 840 }
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
<br />
<CommonFilters filter="gte" />
### `lte()`
<CustomCodeBlock
header="Shows how to use lte( ) with update( )"
js={patchLteJs}
jsHighlight="{10}"
response={`{
"body": [
{ "name": "Mordor", "country_id": 76 },
{ "name": "Mordor", "country_id": 156 },
{ "name": "Mordor", "country_id": 250 }
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
<br />
<CommonFilters filter="lte" />
### `like()`
<CustomCodeBlock
header="Shows how to use like( ) with update( )"
js={patchLikeJs}
jsHighlight="{10}"
response={`{
"body": [
{ "name": "Mordor", "country_id": 554 },
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
<br />
<CommonFilters filter="like" />
### `ilike()`
<CustomCodeBlock
header="Shows how to use ilike( ) with update( )"
js={patchIlikeJs}
jsHighlight="{10}"
response={`{
"body": [
{ "name": "Mordor", "country_id": 554 },
{ "name": "Mordor", "country_id": 556 },
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
<br />
<CommonFilters filter="ilike" />
### `is()`
<CustomCodeBlock
header="Shows how to use is( ) with update( )"
js={patchIsJs}
jsHighlight="{10}"
response={`{
"body": [
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
<br />
<CommonFilters filter="is" />
### `in()`
<CustomCodeBlock
header="Shows how to use in( ) with update( )"
js={patchInJs}
jsHighlight="{10}"
response={`{
"body": [
{ "name": "Mordor", "country_id": 76 },
{ "name": "Mordor", "country_id": 840 }
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
<br />
<CommonFilters filter="in" />
### `cs()`
<CustomCodeBlock
header="Shows how to use cs( ) with update( )"
js={patchCsJs}
jsHighlight="{10}"
response={`{
"body": [
{ "id": 556,
"name": "Mordor",
"population_range_millions": [185, 195]
"main_exports": ["oil", "beans"],
},
{ "id": 840,
"name": "Mordor",
"population_range_millions": [320, 330]
"main_exports": ["oil", "cars", "food"],
}
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
<br />
<CommonFilters filter="cs" />
### `cd()`
<CustomCodeBlock
header="Shows how to use cd( ) with update( )"
js={patchCdJs}
jsHighlight="{10}"
response={`{
"body": [
{ "id": 250,
"name": "Mordor",
"population_range_millions": [60, 70]
"main_exports": ["cars", "machines"],
},
{ "id": 554,
"name": "Mordor",
"population_range_millions": [4, 6]
"main_exports": ["food", "machines"],
}
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
<br />
<CommonFilters filter="cd" />
### `ova()`
<CustomCodeBlock
header="Shows how to use ova( ) with update( )"
js={patchOvaJs}
jsHighlight="{10}"
response={`{
"body": [
{ "id": 76,
"name": "Mordor",
"population_range_millions": [205, 215]
"main_exports": ["beans", "minerals"],
},
{ "id": 156,
"name": "Mordor",
"population_range_millions": [1380, 1390]
"main_exports": ["computers", "phones"],
}
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
<br />
<CommonFilters filter="ova" />
### `ovr()`
<CustomCodeBlock
header="Shows how to use ovr( ) with update( )"
js={patchOvrJs}
jsHighlight="{10}"
response={`{
"body": [
{ "id": 76,
"name": "Mordor",
"population_range_millions": [205, 215]
"main_exports": ["beans", "minerals"],
},
{ "id": 556,
"name": "Mordor",
"population_range_millions": [185, 195]
"main_exports": ["oil", "beans"],
}
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
<br />
<CommonFilters filter="ovr" />
### `sl()`
<CustomCodeBlock
header="Shows how to use sl( ) with update( )"
js={patchSlJs}
jsHighlight="{10}"
response={`{
"body": [
{ "id": 250,
"name": "Mordor",
"population_range_millions": [60, 70]
"main_exports": ["cars", "machines"],
},
{ "id": 554,
"name": "Mordor",
"population_range_millions": [4, 6]
"main_exports": ["food", "machines"],
}
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
<br />
<CommonFilters filter="sl" />
### `sr()`
<CustomCodeBlock
header="Shows how to use sr( ) with update( )"
js={patchSrJs}
jsHighlight="{10}"
response={`{
"body": [
{ "id": 156,
"name": "Mordor",
"population_range_millions": [1380, 1390]
"main_exports": ["computers", "phones"],
},
{ "id": 840,
"name": "Mordor",
"population_range_millions": [320, 330]
"main_exports": ["oil", "cars", "food"],
}
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
<br />
<CommonFilters filter="sr" />
### `nxl()`
<CustomCodeBlock
header="Shows how to use nxl( ) with update( )"
js={patchNxlJs}
jsHighlight="{10}"
response={`{
"body": [
{ "id": 76,
"name": "Mordor",
"population_range_millions": [205, 215]
"main_exports": ["beans", "minerals"],
},
{ "id": 156,
"name": "Mordor",
"population_range_millions": [1380, 1390]
"main_exports": ["computers", "phones"],
},
{ "id": 556,
"name": "Mordor",
"population_range_millions": [185, 195]
"main_exports": ["oil", "beans"],
},
{ "id": 840,
"name": "Mordor",
"population_range_millions": [320, 330]
"main_exports": ["oil", "cars", "food"],
}
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
<br />
<CommonFilters filter="nxl" />
### `nxr()`
<CustomCodeBlock
header="Shows how to use nxr( ) with update( )"
js={patchNxrJs}
jsHighlight="{10}"
response={`{
"body": [
{ "id": 76,
"name": "Mordor",
"population_range_millions": [205, 215]
"main_exports": ["beans", "minerals"],
},
{ "id": 250,
"name": "Mordor",
"population_range_millions": [60, 70]
"main_exports": ["cars", "machines"],
},
{ "id": 554,
"name": "Mordor",
"population_range_millions": [4, 6]
"main_exports": ["food", "machines"],
},
{ "id": 556,
"name": "Mordor",
"population_range_millions": [185, 195]
"main_exports": ["oil", "beans"],
}
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
<br />
<CommonFilters filter="nxr" />
### `adj()`
<CustomCodeBlock
header="Shows how to use adj( ) with update( )"
js={patchAdjJs}
jsHighlight="{10}"
response={`{
"body": [
{ "id": 250,
"name": "Mordor",
"population_range_millions": [60, 70]
"main_exports": ["cars", "machines"],
},
{ "id": 556,
"name": "Mordor",
"population_range_millions": [185, 195]
"main_exports": ["oil", "beans"],
}
],
"status": 200,
"statusCode": 200,
"statusText": "OK"
}`}
/>
<br />
<CommonFilters filter="adj" />
## Responses
#### 200 OK
Successful request
<CommonResponses />