mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 18:05:11 +03:00
## What kind of change does this PR introduce? Updates the docs with the new developer experience: https://deploy-preview-253--supabase.netlify.app/docs - Documents the new Auth using `gotrue-js` - Fixes #179 - Fixes OAuth links https://github.com/supabase/supabase/issues/241#issuecomment-705632335 - [x] Add docs on Policies ## Additional context Related PR on `supabase-js` https://github.com/supabase/supabase-js/pull/50 * Updates the docs for the new Auth DX. * docs: adds docs for subscribing to rows * Updates all the reads * Updates all the docs with the new format * docs: Replaces all { error, data} with data first, because I subjectively think it looks better * Adds some of the breaking changes to a blog post * Adds headings * removes the blog post since it is now in notion * Adds the Oauth changes * removes recharts because we no longer use it * Adds basic structure for GoTrue ref * Adds styles for the api reference docs * Adds more generated docs * Downloads the files to work locally * Adds a supabase generator * Moves some of the guides into the "tools" folder * Re-shuffles some of the pages around * Generated everythign related to the Supabase Client * Refactors and categorieses the pages * Changes the names to be more readable * Migrates almost all of the filters into the API reference * Moves most of the stored procedure filters * Adds realtime-js to the mix * More desciptive titles * Moves all the generated docs to the docs folder * Moves over some of the data manipulators * Extracts most of the client functionality to the API ref * Adds more detail to the guides * Removes the reference to the emulator * Adds the supabase 1.0 blog post * Adds a redirects for netlify * chore: Updates packages * Updates broken links * Adding docs for the server * Adds comments to gotrue and pgapi * Adds a twitter icon to our navbar * Updates the auth with the new user and session return values * Updates the sponsors * Styles for cards * Adds a default value to all of the Tabs
253 lines
4.1 KiB
Plaintext
253 lines
4.1 KiB
Plaintext
---
|
|
id: insert
|
|
title: "Create data: insert()"
|
|
slug: insert
|
|
---
|
|
|
|
import Tabs from '@theme/Tabs';
|
|
import TabItem from '@theme/TabItem';
|
|
|
|
Performs an INSERT into the table.
|
|
|
|
<Tabs
|
|
defaultValue="js"
|
|
groupId="libraries"
|
|
values={[{ label: 'JavaScript', value: 'js' },{ label: 'Python', value: 'py' }]}>
|
|
|
|
<TabItem value="js">
|
|
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.insert([
|
|
{ name: 'The Shire', country_id: 554 }
|
|
])
|
|
```
|
|
|
|
|
|
</TabItem>
|
|
<TabItem value="py">
|
|
|
|
```py
|
|
# Not yet implemented
|
|
```
|
|
|
|
|
|
</TabItem>
|
|
|
|
</Tabs>
|
|
|
|
## Parameters
|
|
|
|
|
|
<ul className="method-list-group">
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
values
|
|
</span>
|
|
<span className="method-list-item-label-badge required">
|
|
required
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
|
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
The values to insert.
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
__namedParameters
|
|
</span>
|
|
<span className="method-list-item-label-badge required">
|
|
required
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
object
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
No description provided.
|
|
|
|
</div>
|
|
|
|
<ul className="method-list-group">
|
|
<h5 class="method-list-title method-list-title-isChild expanded">Properties</h5>
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
onConflict
|
|
</span>
|
|
<span className="method-list-item-label-badge required">
|
|
required
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
|
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
By specifying the `on_conflict` query parameter, you can make UPSERT work on a column(s) that has a UNIQUE constraint.
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
upsert
|
|
</span>
|
|
<span className="method-list-item-label-badge required">
|
|
required
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
boolean
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
If `true`, performs an UPSERT.
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
### Create a record
|
|
|
|
|
|
|
|
<Tabs
|
|
defaultValue="js"
|
|
groupId="libraries"
|
|
values={[{ label: 'JavaScript', value: 'js' },{ label: 'Python', value: 'py' }]}>
|
|
|
|
<TabItem value="js">
|
|
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.insert([
|
|
{ name: 'The Shire', country_id: 554 }
|
|
])
|
|
```
|
|
|
|
|
|
</TabItem>
|
|
<TabItem value="py">
|
|
|
|
```py
|
|
# Not yet implemented
|
|
```
|
|
|
|
|
|
</TabItem>
|
|
|
|
</Tabs>
|
|
|
|
### Bulk create
|
|
|
|
|
|
|
|
<Tabs
|
|
defaultValue="js"
|
|
groupId="libraries"
|
|
values={[{ label: 'JavaScript', value: 'js' },{ label: 'Python', value: 'py' }]}>
|
|
|
|
<TabItem value="js">
|
|
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.insert([
|
|
{ name: 'The Shire', country_id: 554 },
|
|
{ name: 'Rohan', country_id: 555 },
|
|
])
|
|
```
|
|
|
|
|
|
</TabItem>
|
|
<TabItem value="py">
|
|
|
|
```py
|
|
# Not yet implemented
|
|
```
|
|
|
|
|
|
</TabItem>
|
|
|
|
</Tabs>
|
|
|
|
### Upsert
|
|
|
|
For upsert, if set to true, primary key columns would need to be included
|
|
in the data parameter in order for an update to properly happen. Also, primary keys
|
|
used must be natural, not surrogate. There are however,
|
|
[workarounds](https://github.com/PostgREST/postgrest/issues/1118)
|
|
for surrogate primary keys.
|
|
|
|
|
|
<Tabs
|
|
defaultValue="js"
|
|
groupId="libraries"
|
|
values={[{ label: 'JavaScript', value: 'js' },{ label: 'Python', value: 'py' }]}>
|
|
|
|
<TabItem value="js">
|
|
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.insert(
|
|
[
|
|
{ name: 'The Shire', country_id: 554 },
|
|
{ name: 'Rohan', country_id: 555 },
|
|
{ name: 'City by the Bay', country_id:840}
|
|
],
|
|
{ upsert: true })
|
|
```
|
|
|
|
|
|
</TabItem>
|
|
<TabItem value="py">
|
|
|
|
```py
|
|
# Not yet implemented
|
|
```
|
|
|
|
|
|
</TabItem>
|
|
|
|
</Tabs> |