Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Patch examples for #21

Angelico63038efe7ac1
diff --git a/web/docs/library/examples/get.js b/web/docs/library/examples/get.js
index dd8ee91465c..aea77d3b59e 100644
--- a/web/docs/library/examples/get.js
+++ b/web/docs/library/examples/get.js
@@ -143,7 +143,7 @@ const getCities = async () => {
try {
let cities = await supabase
.from('cities')
- .filter({'name', 'eq', 'Paris})
+ .filter({'name', 'eq', 'Paris'})
.select('*')
return cities
} catch (error) {
diff --git a/web/docs/library/examples/patch.js b/web/docs/library/examples/patch.js
index b11195dab8e..997e073ce9b 100644
--- a/web/docs/library/examples/patch.js
+++ b/web/docs/library/examples/patch.js
@@ -7,16 +7,232 @@ import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', '1a2b-3c4d-5e6f-7g8h')
-const updateCountryName = async () => {
+const updateCityName = async () => {
try {
let updates = await supabase
- .from('countries')
+ .from('cities')
.update({ name: 'Middle Earth' })
- .match({ name: 'New Zealand' })
+ .match({ name: 'Auckland' })
return updates
} catch (error) {
console.log('Error: ', error)
}
}
+`
+
+export const patchFilterJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const updateCityName = async () => {
+ try {
+ let cities = await supabase
+ .from('cities')
+ .filter({'name', 'eq', 'Paris'})
+ .update({ name: 'Mordor' })
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
+
+export const patchMatchJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const updateCityName = async () => {
+ try {
+ let cities = await supabase
+ .from('cities')
+ .match({name: 'Beijing', country_id: 156})
+ .update({ name: 'Mordor' })
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
+
+export const patchEqJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const updateCityName = async () => {
+ try {
+ let cities = await supabase
+ .from('cities')
+ .eq('name', 'San Francisco')
+ .update({ name: 'Mordor' })
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
+
+export const patchGtJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const updateCityName = async () => {
+ try {
+ let cities = await supabase
+ .from('cities')
+ .gt('country_id', 250)
+ .update({ name: 'Mordor' })
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
+
+export const patchLtJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const updateCityName = async () => {
+ try {
+ let cities = await supabase
+ .from('cities')
+ .lt('country_id', 250)
+ .update({ name: 'Mordor' })
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
+
+export const patchGteJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const updateCityName = async () => {
+ try {
+ let cities = await supabase
+ .from('cities')
+ .gte('country_id', 250)
+ .update({ name: 'Mordor' })
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
+
+export const patchLteJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const updateCityName = async () => {
+ try {
+ let cities = await supabase
+ .from('cities')
+ .lte('country_id', 250)
+ .update({ name: 'Mordor' })
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
+
+export const patchLikeJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const updateCityName = async () => {
+ try {
+ let cities = await supabase
+ .from('cities')
+ .like('name', '%la%')
+ .update({ name: 'Mordor' })
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
+
+export const patchIlikeJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const updateCityName = async () => {
+ try {
+ let cities = await supabase
+ .from('cities')
+ .ilike('name', '%la%')
+ .update({ name: 'Mordor' })
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
+
+export const patchIsJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const updateCityName = async () => {
+ try {
+ let cities = await supabase
+ .from('cities')
+ .is('name', null)
+ .update({ name: 'Mordor' })
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
+
+export const patchInJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const updateCityName = async () => {
+ try {
+ let cities = await supabase
+ .from('cities')
+ .in('name', ['Rio de Janeiro', 'San Francisco'])
+ .update({ name: 'Mordor' })
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
+`
+
+export const patchNotJs = `
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
+
+const updateCityName = async () => {
+ try {
+ let cities = await supabase
+ .from('cities')
+ .not('name', 'Lagos')
+ .update({ name: 'Mordor' })
+ return cities
+ } catch (error) {
+ console.log('Error: ', error)
+ }
+}
`
\ No newline at end of file
diff --git a/web/docs/library/patch.mdx b/web/docs/library/patch.mdx
index b1d835a7c8f..dcce29e3100 100644
--- a/web/docs/library/patch.mdx
+++ b/web/docs/library/patch.mdx
@@ -11,7 +11,20 @@ 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 } from './examples/patch'
+import { patchRecordJs,
+ patchFilterJs,
+ patchMatchJs,
+ patchEqJs,
+ patchGtJs,
+ patchLtJs,
+ patchGteJs,
+ patchLteJs,
+ patchLikeJs,
+ patchIlikeJs,
+ patchIsJs,
+ patchInJs,
+ patchNotJs
+ } from './examples/patch'
<DummyData />
@@ -23,11 +36,11 @@ import { patchRecordJs } from './examples/patch'
jsHighlight="{7-10}"
response={`{
"body": [
- {"id": 554, "name": "Middle Earth", "iso2": "NZ", "continent": "Oceania"}
+ { "name": "Middle Earth", "country_id": 554 },
],
- "status": 204,
- "statusCode": 204,
- "statusText": "No Content"
+ "status": 200,
+ "statusCode": 200,
+ "statusText": "OK"
}`}
/>
@@ -59,44 +72,262 @@ const options = {
## Filtering
### `filter()`
+
+<CustomCodeBlock
+ header="Shows how to use filter( ) with update( )"
+ js={patchFilterJs}
+ jsHighlight="{9}"
+ response={`{
+ "body": [
+ { "name": "Mordor", "country_id": 250 },
+ ],
+ "status": 200,
+ "statusCode": 200,
+ "statusText": "OK"
+}`}
+/>
+
+<br/>
+
<CommonFilters filter='filter'/>
### `match()`
+
+<CustomCodeBlock
+ header="Shows how to use match( ) with update( )"
+ js={patchMatchJs}
+ jsHighlight="{9}"
+ 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="{9}"
+ response={`{
+ "body": [
+ { "name": "Mordor", "country_id": 840 },
+ ],
+ "status": 200,
+ "statusCode": 200,
+ "statusText": "OK"
+}`}
+/>
+
+<br/>
+
<CommonFilters filter='eq'/>
### `gt()`
+
+<CustomCodeBlock
+ header="Shows how to use gt( ) with update( )"
+ js={patchGtJs}
+ jsHighlight="{9}"
+ response={`{
+ "body": [
+ { "name": "Mordor", "country_id": 554 },
+ { "name": "Mordor", "country_id": 556 },
+ { "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="{9}"
+ 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="{9}"
+ response={`{
+ "body": [
+ { "name": "Mordor", "country_id": 250 },
+ { "name": "Mordor", "country_id": 554 },
+ { "name": "Mordor", "country_id": 556 },
+ { "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="{9}"
+ 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="{9}"
+ 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="{9}"
+ 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="{9}"
+ 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="{9}"
+ response={`{
+ "body": [
+ { "name": "Mordor", "country_id": 76 },
+ { "name": "Mordor", "country_id": 840 }
+ ],
+ "status": 200,
+ "statusCode": 200,
+ "statusText": "OK"
+}`}
+/>
+
+<br/>
+
<CommonFilters filter='in'/>
### `not()`
+
+<CustomCodeBlock
+ header="Shows how to use not( ) with update( )"
+ js={patchNotJs}
+ jsHighlight="{9}"
+ 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 }
+ ],
+ "status": 200,
+ "statusCode": 200,
+ "statusText": "OK"
+}`}
+/>
+
+<br/>
+
<CommonFilters filter='not'/>
## Responses
#### 200 OK
-Successful
+Successful request
<CommonResponses />
\ No newline at end of file