mirror of
https://github.com/supabase/supabase.git
synced 2026-10-19 16:19:10 +03:00
107 lines
1.8 KiB
Plaintext
107 lines
1.8 KiB
Plaintext
---
|
|
id: post
|
|
title: 'Creating'
|
|
---
|
|
|
|
|
|
import DummyData from '../common/DummyData.mdx'
|
|
import Collapsable from '../../src/components/Collapsable'
|
|
import CommonResponses from '../common/CommonResponses.mdx'
|
|
|
|
|
|
We will be using these tables as reference for our examples:
|
|
|
|
<DummyData />
|
|
|
|
|
|
|
|
### Create a record
|
|
|
|
This example how to create a new city:
|
|
|
|
<!-- prettier-ignore -->
|
|
```js {7-8}
|
|
import { createClient } from '@supabase/supabase-js'
|
|
|
|
const supabase = createClient('https://world.supabase.io', '1a2b-3c4d-5e6f-7g8h')
|
|
|
|
const getCities = async () => {
|
|
try {
|
|
let cities = await supabase
|
|
.post('cities', [
|
|
{ name: 'The Shire', country_id: 554 }
|
|
])
|
|
return cities
|
|
} catch (error) {
|
|
console.log('Error: ', error)
|
|
}
|
|
}
|
|
```
|
|
|
|
<Collapsable title="Toggle Example Response">
|
|
|
|
@todo
|
|
|
|
</Collapsable>
|
|
|
|
### Bulk create
|
|
|
|
This example how to create multiple cities with one request:
|
|
|
|
<!-- prettier-ignore -->
|
|
```js {7-8}
|
|
import { createClient } from '@supabase/supabase-js'
|
|
|
|
const supabase = createClient('https://world.supabase.io', '1a2b-3c4d-5e6f-7g8h')
|
|
|
|
const createCities = async () => {
|
|
try {
|
|
let cities = await supabase
|
|
.post('cities', [
|
|
{ name: 'The Shire', country_id: 554 },
|
|
{ name: 'Rohan', country_id: 554 },
|
|
])
|
|
return cities
|
|
} catch (error) {
|
|
console.log('Error: ', error)
|
|
}
|
|
}
|
|
```
|
|
|
|
<Collapsable title="Toggle Example Response">
|
|
|
|
@todo
|
|
|
|
</Collapsable>
|
|
|
|
|
|
|
|
|
|
## Reference
|
|
|
|
|
|
|
|
### `post()`
|
|
```js
|
|
supabase
|
|
.post(tableName, data, options?)
|
|
```
|
|
|
|
##### tableName `:string`
|
|
Name of table in the database where data will be saved.
|
|
|
|
##### data `:array`
|
|
Array of rows of type `object` which contain information to be saved into the selected table.
|
|
|
|
|
|
##### options `:object?`
|
|
@todo
|
|
|
|
|
|
|
|
## Responses
|
|
|
|
#### 201 Created
|
|
Successful
|
|
|
|
<CommonResponses /> |