mirror of
https://github.com/supabase/supabase.git
synced 2026-07-05 05:14:21 +08:00
2159 lines
72 KiB
YAML
2159 lines
72 KiB
YAML
openref: 0.1
|
|
|
|
info:
|
|
id: reference/supabase-js
|
|
title: Supabase Client
|
|
description: |
|
|
|
|
Our client library is modular. Each sub-library is a standalone implementation for a single external system. This is one of the ways we support existing tools.
|
|
|
|
|
|
| Repo | Official | Community |
|
|
|-----------------------|--------------------------------------------------|------------------|
|
|
| **`supabase-{lang}`** <br /> Combines libraries and adds enrichments. | [`JavaScript`](https://github.com/supabase/supabase-js) | [`C#`](https://github.com/supabase/supabase-csharp), [`Python`](https://github.com/supabase/supabase-py), `Rust`, [`Dart`](https://github.com/supabase/supabase-dart) |
|
|
| `postgrest-{lang}` <br /> Client library to work with [PostgREST](https://github.com/postgrest/postgrest) | [`JavaScript`](https://github.com/supabase/postgrest-js) | [`C#`](https://github.com/supabase/postgrest-csharp), [`Python`](https://github.com/supabase/postgrest-py), [`Rust`](https://github.com/supabase/postgrest-rs), [`Kotlin`](https://github.com/supabase/postgrest-kt), [`Dart`](https://github.com/supabase/postgrest-dart) |
|
|
| `realtime-{lang}` <br /> Client library to work with [Realtime](https://github.com/supabase/realtime) | [`JavaScript`](https://github.com/supabase/realtime-js) | `C#`, `Python`, `Rust`, [`Dart`](https://github.com/supabase/realtime-dart) |
|
|
| `gotrue-{lang}` <br /> Client library to work with [GoTrue](https://github.com/netlify/gotrue) | [`JavaScript`](https://github.com/supabase/gotrue-js) | `C#`, `Python`, `Rust`, [`Kotlin`](https://github.com/supabase/gotrue-kt), [`Dart`](https://github.com/supabase/gotrue-dart) |
|
|
|
|
definition: spec/combined.json
|
|
libraries:
|
|
- name: 'JavaScript'
|
|
id: 'js'
|
|
version: '0.0.1'
|
|
docs:
|
|
path: reference/javascript/
|
|
sidebar:
|
|
- name: 'About'
|
|
items:
|
|
- index
|
|
- Installing
|
|
- Initializing
|
|
- Generating Types
|
|
- name: 'Auth'
|
|
items:
|
|
- auth.signUp()
|
|
- auth.signIn()
|
|
- auth.signOut()
|
|
- auth.session()
|
|
- auth.user()
|
|
- auth.update()
|
|
- auth.onAuthStateChange()
|
|
- Reset Password (Email)
|
|
- Delete User
|
|
- name: 'Data'
|
|
items:
|
|
- select()
|
|
- insert()
|
|
- update()
|
|
- upsert()
|
|
- delete()
|
|
- rpc()
|
|
- name: 'Realtime'
|
|
items:
|
|
- subscribe()
|
|
- removeSubscription()
|
|
- getSubscriptions()
|
|
- name: 'Storage'
|
|
items:
|
|
- storage.createBucket()
|
|
- storage.getBucket()
|
|
- storage.listBuckets()
|
|
- storage.updateBucket()
|
|
- storage.deleteBucket()
|
|
- storage.emptyBucket()
|
|
- storage.from.upload()
|
|
- storage.from.download()
|
|
- storage.from.list()
|
|
- storage.from.update()
|
|
- storage.from.move()
|
|
- storage.from.remove()
|
|
- storage.from.createSignedUrl()
|
|
- storage.from.getPublicUrl()
|
|
- name: 'Modifiers'
|
|
items:
|
|
- Using Modifiers
|
|
- limit()
|
|
- order()
|
|
- range()
|
|
- single()
|
|
- name: 'Filters'
|
|
items:
|
|
- Using Filters
|
|
- .filter()
|
|
- .or()
|
|
- .not()
|
|
- .match()
|
|
- .eq()
|
|
- .neq()
|
|
- .gt()
|
|
- .gte()
|
|
- .lt()
|
|
- .lte()
|
|
- .like()
|
|
- .ilike()
|
|
- .is()
|
|
- .in()
|
|
- .contains()
|
|
- .containedBy()
|
|
- .rangeLt()
|
|
- .rangeGt()
|
|
- .rangeGte()
|
|
- .rangeLte()
|
|
- .rangeAdjacent()
|
|
- .overlaps()
|
|
- .textSearch()
|
|
|
|
pages:
|
|
Installing:
|
|
description: |
|
|
All JavaScript libraries are built directly by the Supabase team.
|
|
|
|
Other languages are built by the community and supported by Supabase.
|
|
|
|
## JavaScript
|
|
|
|
Via NPM
|
|
```bash
|
|
npm install @supabase/supabase-js
|
|
```
|
|
|
|
Find the source code on [GitHub](https://github.com/supabase/supabase-js).
|
|
|
|
Or via CDN
|
|
```js
|
|
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js"></script>
|
|
//or
|
|
<script src="https://unpkg.com/@supabase/supabase-js"></script>
|
|
```
|
|
|
|
## Python
|
|
|
|
```bash
|
|
pip install supabase-py
|
|
```
|
|
|
|
Find the source code on [GitHub](https://github.com/supabase/supabase-py).
|
|
|
|
Initializing:
|
|
$ref: '@supabase/supabase-js."SupabaseClient".SupabaseClient.constructor'
|
|
description: |
|
|
You can initialize a new Supabase client using the `createClient()` method.
|
|
|
|
The Supabase client is your entrypoint to the rest of the Supabase functionality
|
|
and is the easiest way to interact with everything we offer within the Supabase ecosystem.
|
|
|
|
examples:
|
|
- name: createClient()
|
|
js: |
|
|
```js
|
|
import { createClient } from '@supabase/supabase-js'
|
|
|
|
// Create a single supabase client for interacting with your database
|
|
const supabase = createClient("https://xyzcompany.supabase.co", "public-anon-key")
|
|
```
|
|
- name: With additional parameters
|
|
js: |
|
|
```js
|
|
import { createClient } from '@supabase/supabase-js'
|
|
|
|
const options = { }
|
|
const supabase = createClient("https://xyzcompany.supabase.co", "public-anon-key", options)
|
|
```
|
|
|
|
Generating Types:
|
|
description: |
|
|
Supabase will soon release native type generators that dump your database types for various languages. For now, we support TypeScript through a third-party tool.
|
|
|
|
## Usage with TypeScript
|
|
|
|
`supabase-js` ships with type definitions for usage with TypeScript and for convenient IntelliSense auto-complete and documentation in your editor.
|
|
|
|
When using TypeScript, you can pass the type of database row as a type parameter to the `from` method to get better auto-completion support down the chain.
|
|
If you don't provide a type for the row you need to explicitly pass `from<any>('tableName')`.
|
|
|
|
```ts
|
|
type Message = {
|
|
id: number;
|
|
inserted_at: string;
|
|
message: string;
|
|
user_id: string;
|
|
channel_id: number;
|
|
author: { username: string };
|
|
}
|
|
|
|
const response = await supabase
|
|
.from<Message>('messages') // Message maps to the type of the row in your database.
|
|
.select('*, author:user_id(username)')
|
|
.match({ channel_id: 2 }) // Your IDE will be able to help with auto-completion.
|
|
response.data // Response data will be of type Array<Message>.
|
|
|
|
// If you don't provide a type for the row you need to explicitly pass `from<any>('tableName')`.
|
|
const response = await supabase
|
|
.from<any>('messages')
|
|
.select('*, author:user_id(username)')
|
|
.match({ channel_id: 2 })
|
|
response.data // Response data will be of type Array<any>.
|
|
```
|
|
|
|
### Generate database types from OpenAPI specification
|
|
|
|
Supabase generates a OpenAPI specification file for your database which can be used to generate your data types for usage with TypeScript.
|
|
|
|
The OpenAPI specification for your Supabase project can be accessed as follows:
|
|
|
|
```txt
|
|
https://your-project.supabase.co/rest/v1/?apikey=your-anon-key
|
|
```
|
|
|
|
Using the open source [openapi-typescript](https://github.com/drwpow/openapi-typescript#%EF%B8%8F-reading-specs-from-remote-resource) tool you can generate your types and store them locally:
|
|
|
|
```bash
|
|
npx openapi-typescript https://your-project.supabase.co/rest/v1/?apikey=your-anon-key --output types/supabase.ts
|
|
```
|
|
|
|
Important notes:
|
|
|
|
- Since the generator uses JSON API, there is no way to determine if a column is an Array. It will generate array types as `string`, even though Supabase handles this automatically and returns arrays.
|
|
You can fix this manually in the files by changing the type, e.g. `names: string` -> `names: string[]`
|
|
- The types won't automatically stay in sync with your database, so make sure to regenerate your types after your make changes to your database.
|
|
|
|
After you have generated your types, you can use them in your TypeScript projects:
|
|
|
|
```ts
|
|
import { NextApiRequest, NextApiResponse } from "next";
|
|
import { createClient } from "@supabase/supabase-js";
|
|
import { definitions } from "../../types/supabase";
|
|
|
|
const supabase = createClient(
|
|
process.env.NEXT_PUBLIC_SUPABASE_URL,
|
|
process.env.SUPABASE_SECRET_KEY
|
|
);
|
|
|
|
export default async (req: NextApiRequest, res: NextApiResponse) => {
|
|
const allOnlineUsers = await supabase
|
|
.from<definitions["users"]>("users")
|
|
.select("*")
|
|
.eq("status", "ONLINE");
|
|
res.status(200).json(allOnlineUsers);
|
|
};
|
|
```
|
|
|
|
### Update types automatically with GitHub Actions
|
|
|
|
One way to keep your type definitions in sync with your database is to set up a GitHub action that runs on a schedule.
|
|
|
|
Add a script to your package.json to generate the types:
|
|
|
|
```
|
|
"update-types": "npx openapi-typescript https://your-project.supabase.co/rest/v1/?apikey=your-anon-key --output types/database/index.ts"
|
|
```
|
|
|
|
In your repo, create the file `.github/workflows/update-types.yml`. Add the following snippet into this file to define the action. If there is a change to your definitions, this script will commit the change to your repo.
|
|
|
|
```yml
|
|
name: Update database types
|
|
|
|
on:
|
|
schedule:
|
|
# sets the action to run daily. You can modify this to run the action more or less freqently
|
|
- cron: '0 0 * * *'
|
|
|
|
jobs:
|
|
update:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v2
|
|
with:
|
|
persist-credentials: false
|
|
fetch-depth: 0
|
|
- uses: actions/setup-node@v2.1.5
|
|
with:
|
|
node-version: 14
|
|
- run: npm run update-types
|
|
- name: check for file changes
|
|
id: git_status
|
|
run: |
|
|
echo "::set-output name=status::$(git status -s)"
|
|
- name: Commit files
|
|
if: ${{contains(steps.git_status.outputs.status, ' ')}}
|
|
run: |
|
|
git add types/database/index.ts
|
|
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
git config --local user.name "github-actions[bot]"
|
|
git commit -m "Update database types" -a
|
|
- name: Push changes
|
|
if: ${{contains(steps.git_status.outputs.status, ' ')}}
|
|
uses: ad-m/github-push-action@master
|
|
with:
|
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
branch: ${{ github.ref }}
|
|
```
|
|
|
|
auth.signUp():
|
|
$ref: '@supabase/gotrue-js."GoTrueClient".GoTrueClient.signUp'
|
|
notes: |
|
|
- By default, the user will need to verify their email address before logging in. If you would like to change this, you can disable "Email Confirmations" by going to Authentication -> Settings on [app.supabase.io](https://app.supabase.io)
|
|
- If "Email Confirmations" is turned on, a `user` is returned but `session` will be null
|
|
- If "Email Confirmations" is turned off, both a `user` and a `session` will be returned
|
|
- When the user confirms their email address, they will be redirected to localhost:3000 by default. To change this, you can go to Authentication -> Settings on [app.supabase.io](https://app.supabase.io)
|
|
examples:
|
|
- name: Sign up.
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { user, session, error } = await supabase.auth.signUp({
|
|
email: 'example@email.com',
|
|
password: 'example-password',
|
|
})
|
|
```
|
|
- name: Sign up with third-party providers.
|
|
hideCodeBlock: true
|
|
description: |
|
|
You can sign up with OAuth providers using the [`signIn()`](/docs/reference/javascript/auth-signin#sign-in-using-third-party-providers) method.
|
|
|
|
auth.signIn():
|
|
$ref: '@supabase/gotrue-js."GoTrueClient".GoTrueClient.signIn'
|
|
notes: |
|
|
- A user can sign up either via email or OAuth.
|
|
- If you provide `email` without a `password`, the user will be sent a magic link.
|
|
- The magic link's destination URL is determined by the SITE_URL config variable. To change this, you can go to Authentication -> Settings on [app.supabase.io](https://app.supabase.io)
|
|
- Specifying a `provider` will open the browser to the relevant login page.
|
|
examples:
|
|
- name: Sign in with email.
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { user, session, error } = await supabase.auth.signIn({
|
|
email: 'example@email.com',
|
|
password: 'example-password',
|
|
})
|
|
```
|
|
- name: Sign in with magic link.
|
|
description: If no password is provided, the user will be sent a "magic link" to their email address, which they can click to open your application with a valid session. By default, a given user can only request a Magic Link once every 60 seconds.
|
|
js: |
|
|
```js
|
|
const { user, session, error } = await supabase.auth.signIn({
|
|
email: 'example@email.com'
|
|
})
|
|
```
|
|
- name: Sign in using third-party providers.
|
|
description: Supabase supports OAuth logins.
|
|
js: |
|
|
```js
|
|
const { user, session, error } = await supabase.auth.signIn({
|
|
// provider can be 'github', 'google', 'gitlab', or 'bitbucket'
|
|
provider: 'github'
|
|
})
|
|
```
|
|
- name: Sign in with redirect.
|
|
description: |
|
|
Sometimes you want to control where the user is redirected to after they are logged in. Supabase supports this for
|
|
any URL path on your website (the base domain must be the same as the domain in your Auth settings).
|
|
js: |
|
|
```js
|
|
const { user, session, error } = await supabase.auth.signIn({
|
|
provider: 'github'
|
|
}, {
|
|
redirectTo: 'https://example.com/welcome'
|
|
})
|
|
```
|
|
- name: Sign in with scopes.
|
|
description: |
|
|
If you need additional data from an OAuth provider, you can include a space-separated list of scopes in your request to get back an OAuth provider token.
|
|
You may also need to specify the scopes in the provider's OAuth app settings, depending on the provider.
|
|
js: |
|
|
```js
|
|
const { user, session, error } = await supabase.auth.signIn({
|
|
provider: 'github'
|
|
}, {
|
|
scopes: 'repo gist notifications'
|
|
})
|
|
const oAuthToken = session.provider_token // use to access provider API
|
|
```
|
|
- name: Sign in using a refresh token (e.g. in React Native).
|
|
description: |
|
|
If you are completing a sign up or login in a React Native app you can pass the refresh token obtained from the provider to obtain a session.
|
|
js: |
|
|
```js
|
|
// An example using Expo's `AuthSession`
|
|
const redirectUri = AuthSession.makeRedirectUri({ useProxy: false });
|
|
const provider = 'google';
|
|
|
|
AuthSession.startAsync({
|
|
authUrl: `https://MYSUPABASEAPP.supabase.co/auth/v1/authorize?provider=${provider}&redirect_to=${redirectUri}`,
|
|
returnUrl: redirectUri,
|
|
}).then(async (response: any) => {
|
|
if (!response) return;
|
|
const { user, session, error } = await supabase.auth.signIn({
|
|
refreshToken: response.params?.refresh_token,
|
|
});
|
|
});
|
|
```
|
|
|
|
auth.signOut():
|
|
$ref: '@supabase/gotrue-js."GoTrueClient".GoTrueClient.signOut'
|
|
examples:
|
|
- name: Sign out
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { error } = await supabase.auth.signOut()
|
|
```
|
|
|
|
auth.session():
|
|
$ref: '@supabase/gotrue-js."GoTrueClient".GoTrueClient.session'
|
|
examples:
|
|
- name: Get the session data
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const session = supabase.auth.session()
|
|
```
|
|
|
|
auth.user():
|
|
$ref: '@supabase/gotrue-js."GoTrueClient".GoTrueClient.user'
|
|
examples:
|
|
- name: Get the logged in user
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const user = supabase.auth.user()
|
|
```
|
|
|
|
auth.update():
|
|
$ref: '@supabase/gotrue-js."GoTrueClient".GoTrueClient.update'
|
|
notes: |
|
|
It's generally better to store user data in a table inside your public schema (i.e. `public.users`).
|
|
Use the `update()` method if you have data which rarely changes or is specific only to the logged in user.
|
|
examples:
|
|
- name: Update a user's metadata.
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { user, error } = await supabase.auth.update({
|
|
data: { hello: 'world' }
|
|
})
|
|
```
|
|
|
|
auth.onAuthStateChange():
|
|
$ref: '@supabase/gotrue-js."GoTrueClient".GoTrueClient.onAuthStateChange'
|
|
examples:
|
|
- name: Listen to auth changes
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
supabase.auth.onAuthStateChange((event, session) => {
|
|
console.log(event, session)
|
|
})
|
|
```
|
|
|
|
Reset Password (Email):
|
|
$ref: '@supabase/gotrue-js."GoTrueApi".GoTrueApi.resetPasswordForEmail'
|
|
notes: |
|
|
Sends a reset request to an email address.
|
|
|
|
When the user clicks the reset link in the email they will be forwarded to:
|
|
|
|
`<SITE_URL>#access_token=x&refresh_token=y&expires_in=z&token_type=bearer&type=recovery`
|
|
|
|
Your app must detect `type=recovery` in the fragment and display a password reset form to the user.
|
|
|
|
You should then use the access_token in the url and new password to update the user as follows:
|
|
|
|
```js
|
|
const { error, data } = await supabase.auth.api
|
|
.updateUser(access_token, { password : new_password })
|
|
```
|
|
examples:
|
|
- name: Reset password
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = supabase.auth.api.resetPasswordForEmail('user@email.com')
|
|
```
|
|
|
|
Delete User:
|
|
$ref: '@supabase/gotrue-js."GoTrueApi".GoTrueApi.deleteUser'
|
|
examples:
|
|
- name: Remove a user completely.
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { user, error } = await supabase.auth.api.deleteUser(
|
|
'715ed5db-f090-4b8c-a067-640ecee36aa0',
|
|
'YOUR_SERVICE_ROLE_KEY'
|
|
)
|
|
```
|
|
|
|
select():
|
|
title: 'Fetch data: select()'
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestQueryBuilder".PostgrestQueryBuilder.select'
|
|
notes: |
|
|
- By default, Supabase projects will return a maximum of 1,000 rows. This setting can be changed Project API Settings. It's recommended that you keep it low to limit the payload size of accidental or malicious requests. You can use `range()` queries to paginate through your data.
|
|
- `select()` can be combined with [Modifiers](/docs/reference/javascript/using-modifiers)
|
|
- `select()` can be combined with [Filters](/docs/reference/javascript/using-filters)
|
|
examples:
|
|
- name: Getting your data
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select()
|
|
```
|
|
- name: Selecting specific columns
|
|
description: You can select specific fields from your tables.
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name')
|
|
```
|
|
- name: Query foreign tables
|
|
description: If your database has relationships, you can query related tables too.
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.select(`
|
|
name,
|
|
cities (
|
|
name
|
|
)
|
|
`)
|
|
```
|
|
- name: Query the same foreign table multiple times
|
|
description: |
|
|
Sometimes you will need to query the same foreign table twice.
|
|
In this case, you can use the name of the joined column to identify
|
|
which join you intend to use. For convenience, you can also give an
|
|
alias for each column. For example, if we had a shop of products,
|
|
and we wanted to get the supplier and the purchaser at the same time
|
|
(both in the users) table:
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('products')
|
|
.select(`
|
|
id,
|
|
supplier:supplier_id ( name ),
|
|
purchaser:purchaser_id ( name )
|
|
`)
|
|
```
|
|
- name: Querying with count option
|
|
description: |
|
|
You can get the number of rows by using the count option.
|
|
Allowed values for count option are `null`, [exact](https://postgrest.org/en/stable/api.html#exact-count), [planned](https://postgrest.org/en/stable/api.html#planned-count) and [estimated](https://postgrest.org/en/stable/api.html#estimated-count).
|
|
js: |
|
|
```js
|
|
const { data, error, count } = await supabase
|
|
.from('cities')
|
|
.select('name', {}, { count: 'exact' }) // if you don't want to return any rows, you can use { count: 'exact', head: true }
|
|
```
|
|
- name: Querying JSON data
|
|
description: |
|
|
If you have data inside of a JSONB column, you can apply select
|
|
and query filters to the data values. Postgres offers a
|
|
[number of operators](https://www.postgresql.org/docs/current/functions-json.html)
|
|
for querying JSON data. Also see
|
|
[PostgREST docs](http://postgrest.org/en/v7.0.0/api.html#json-columns) for more details.
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('users')
|
|
.select(`
|
|
id, name,
|
|
address->street
|
|
`)
|
|
.eq('address->postcode', 90210)
|
|
```
|
|
- name: Return data as CSV
|
|
description: |
|
|
By default the data is returned in JSON format, however you can also request for it to be returned as Comma Separated Values.
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('users')
|
|
.select()
|
|
.csv()
|
|
```
|
|
|
|
insert():
|
|
title: 'Create data: insert()'
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestQueryBuilder".PostgrestQueryBuilder.insert'
|
|
notes: |
|
|
- By default, every time you run `insert()`, the client library will make a `select` to return the full record.
|
|
This is convenient, but it can also cause problems if your Policies are not configured to allow the `select` operation.
|
|
If you are using Row Level Security and you are encountering problems, try setting the `returning` param to `minimal`.
|
|
examples:
|
|
- name: Create a record
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.insert([
|
|
{ name: 'The Shire', country_id: 554 }
|
|
])
|
|
```
|
|
- name: Bulk create
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.insert([
|
|
{ name: 'The Shire', country_id: 554 },
|
|
{ name: 'Rohan', country_id: 555 },
|
|
])
|
|
```
|
|
- name: Upsert
|
|
description: |
|
|
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.
|
|
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 })
|
|
```
|
|
|
|
update():
|
|
title: 'Modify data: update()'
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestQueryBuilder".PostgrestQueryBuilder.update'
|
|
notes: |
|
|
- `update()` should always be combined with [Filters](/docs/reference/javascript/using-filters) to target the item(s) you wish to update.
|
|
examples:
|
|
- name: Updating your data
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.update({ name: 'Middle Earth' })
|
|
.match({ name: 'Auckland' })
|
|
```
|
|
- name: Updating JSON data
|
|
description: |
|
|
Postgres offers a
|
|
[number of operators](https://www.postgresql.org/docs/current/functions-json.html)
|
|
for working with JSON data. Right now it is only possible to update an entire JSON document,
|
|
but we are [working on ideas](https://github.com/PostgREST/postgrest/issues/465) for updating individual keys.
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('users')
|
|
.update(`
|
|
address: {
|
|
street: 'Melrose Place',
|
|
postcode: 90210
|
|
}
|
|
`)
|
|
.eq('address->postcode', 90210)
|
|
```
|
|
|
|
upsert():
|
|
title: 'Upsert data: upsert()'
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestQueryBuilder".PostgrestQueryBuilder.upsert'
|
|
notes: |
|
|
- Primary keys should to be included in the data payload in order for an update to work correctly.
|
|
- Primary keys must be natural, not surrogate. There are however, [workarounds](https://github.com/PostgREST/postgrest/issues/1118) for surrogate primary keys.
|
|
examples:
|
|
- name: Upsert your data
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('messages')
|
|
.upsert({ id: 3, message: 'foo', username: 'supabot' })
|
|
```
|
|
- name: Upserting into tables with constraints
|
|
description: |
|
|
Running the following will cause supabase to upsert data into the `users` table.
|
|
If the username 'supabot' already exists, the `onConflict` argument tells supabase to overwrite that row
|
|
based on the column passed into `onConflict`.
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('users')
|
|
.upsert({ username: 'supabot' }, { onConflict: 'username' })
|
|
```
|
|
- name: Return the exact number of rows
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error, count } = await supabase
|
|
.from('users')
|
|
.upsert({
|
|
id: 3, message: 'foo',
|
|
username: 'supabot'
|
|
}, {
|
|
count: 'exact'
|
|
})
|
|
```
|
|
|
|
delete():
|
|
title: 'Delete data: delete()'
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestQueryBuilder".PostgrestQueryBuilder.delete'
|
|
notes: |
|
|
- `delete()` should always be combined with [filters](/docs/reference/javascript/using-filters) to target the item(s) you wish to delete.
|
|
- If you use `delete()` with filters and you have
|
|
[RLS](/docs/learn/auth-deep-dive/auth-row-level-security) enabled, only
|
|
rows visible through `SELECT` policies are deleted. Note that by default
|
|
no rows are visible, so you need at least one `SELECT`/`ALL` policy that
|
|
makes the rows visible.
|
|
examples:
|
|
- name: Delete records
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.delete()
|
|
.match({ id: 666 })
|
|
```
|
|
|
|
rpc():
|
|
title: 'Postgres functions: rpc()'
|
|
description: |
|
|
You can call Postgres functions as a "Remote Procedure Call".
|
|
|
|
That's a fancy way of saying that you can put some logic into your database then call it from anywhere.
|
|
It's especially useful when the logic rarely changes - like password resets and updates.
|
|
$ref: '@supabase/postgrest-js."PostgrestClient".PostgrestClient.rpc'
|
|
examples:
|
|
- name: Call a Postgres function
|
|
isSpotlight: true
|
|
description: This is an example invoking a Postgres function.
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.rpc('hello_world')
|
|
```
|
|
- name: With Parameters
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.rpc('echo_city', { name: 'The Shire' })
|
|
```
|
|
- name: Bulk processing
|
|
description: You can process large payloads at once using [array parameters](https://postgrest.org/en/stable/api.html#calling-functions-with-array-parameters).
|
|
js: |
|
|
```js
|
|
const { data, error } = await postgrest
|
|
.rpc('echo_cities', { names: ['The Shire', 'Mordor'] })
|
|
```
|
|
- name: With filters
|
|
description: |
|
|
Postgres functions that return tables can also be combined with
|
|
[Modifiers](/docs/reference/javascript/using-modifiers) and
|
|
[Filters](/docs/reference/javascript/using-filters).
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.rpc('echo_all_cities')
|
|
.eq('name', 'The Shire')
|
|
```
|
|
- name: With count option
|
|
description: |
|
|
You can specify a count option to get the row count along with your data.
|
|
Allowed values for count option are `null`, `exact`, `planned` and `estimated`.
|
|
js: |
|
|
```js
|
|
const { data, error, count } = await supabase
|
|
.rpc('hello_world', {}, { count: 'exact' })
|
|
```
|
|
|
|
subscribe():
|
|
title: 'on().subscribe()'
|
|
$ref: '@supabase/supabase-js."lib/SupabaseQueryBuilder".SupabaseQueryBuilder.on'
|
|
notes: |
|
|
- Realtime is disabled by default for new Projects for better database performance and security. You can turn it on by [managing replication](/docs/guides/api#managing-realtime).
|
|
- If you want to receive the "previous" data for updates and deletes, you will need to set `REPLICA IDENTITY` to `FULL`, like this: `ALTER TABLE your_table REPLICA IDENTITY FULL;`
|
|
examples:
|
|
- name: Listen to all database changes
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const mySubscription = supabase
|
|
.from('*')
|
|
.on('*', payload => {
|
|
console.log('Change received!', payload)
|
|
})
|
|
.subscribe()
|
|
```
|
|
- name: Listening to a specific table
|
|
js: |
|
|
```js
|
|
const mySubscription = supabase
|
|
.from('countries')
|
|
.on('*', payload => {
|
|
console.log('Change received!', payload)
|
|
})
|
|
.subscribe()
|
|
```
|
|
- name: Listening to inserts
|
|
js: |
|
|
```js
|
|
const mySubscription = supabase
|
|
.from('countries')
|
|
.on('INSERT', payload => {
|
|
console.log('Change received!', payload)
|
|
})
|
|
.subscribe()
|
|
```
|
|
- name: Listening to updates
|
|
description: |
|
|
By default, Supabase will send only the updated record. If you want to receive the previous values as well you can
|
|
enable full replication for the table you are listening too:
|
|
|
|
```sql
|
|
alter table "your_table" replica identity full;
|
|
```
|
|
js: |
|
|
```js
|
|
const mySubscription = supabase
|
|
.from('countries')
|
|
.on('UPDATE', payload => {
|
|
console.log('Change received!', payload)
|
|
})
|
|
.subscribe()
|
|
```
|
|
- name: Listening to deletes
|
|
description: |
|
|
By default, Supabase does not send deleted records. If you want to receive the deleted record you can
|
|
enable full replication for the table you are listening too:
|
|
|
|
```sql
|
|
alter table "your_table" replica identity full;
|
|
```
|
|
js: |
|
|
```js
|
|
const mySubscription = supabase
|
|
.from('countries')
|
|
.on('DELETE', payload => {
|
|
console.log('Change received!', payload)
|
|
})
|
|
.subscribe()
|
|
```
|
|
- name: Listening to multiple events
|
|
description: You can chain listeners if you want to listen to multiple events for each table.
|
|
js: |
|
|
```js
|
|
const mySubscription = supabase
|
|
.from('countries')
|
|
.on('INSERT', handleRecordInserted)
|
|
.on('DELETE', handleRecordDeleted)
|
|
.subscribe()
|
|
```
|
|
- name: Listening to row level changes
|
|
description: You can listen to individual rows using the format `{table}:{col}=eq.{val}` - where `{col}` is the column name, and `{val}` is the value which you want to match.
|
|
js: |
|
|
```js
|
|
const mySubscription = supabase
|
|
.from('countries:id=eq.200')
|
|
.on('UPDATE', handleRecordUpdated)
|
|
.subscribe()
|
|
```
|
|
|
|
removeSubscription():
|
|
title: 'removeSubscription()'
|
|
$ref: '@supabase/supabase-js."SupabaseClient".SupabaseClient.removeSubscription'
|
|
notes: |
|
|
- Removing subscriptions is a great way to maintain the performance of your project's database. Supabase will automatically handle cleanup 30 seconds after a user is disconnected, but unused subscriptions may cause degradation as more users are simultaneously subscribed.
|
|
examples:
|
|
- name: Remove a subscription
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
supabase.removeSubscription(mySubscription)
|
|
```
|
|
|
|
getSubscriptions():
|
|
title: 'getSubscriptions()'
|
|
$ref: '@supabase/supabase-js."SupabaseClient".SupabaseClient.getSubscriptions'
|
|
examples:
|
|
- name: Get all subscriptions
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const subscriptions = supabase.getSubscriptions()
|
|
```
|
|
|
|
storage.listBuckets():
|
|
title: 'listBuckets()'
|
|
$ref: '@supabase/storage-js."lib/StorageBucketApi".StorageBucketApi.listBuckets'
|
|
notes: |
|
|
- Policy permissions required:
|
|
- `buckets` permissions: `select`
|
|
- `objects` permissions: none
|
|
examples:
|
|
- name: List buckets
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.storage
|
|
.listBuckets()
|
|
```
|
|
|
|
storage.getBucket():
|
|
title: 'getBucket()'
|
|
$ref: '@supabase/storage-js."lib/StorageBucketApi".StorageBucketApi.getBucket'
|
|
notes: |
|
|
- Policy permissions required:
|
|
- `buckets` permissions: `select`
|
|
- `objects` permissions: none
|
|
examples:
|
|
- name: Get bucket
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.storage
|
|
.getBucket('avatars')
|
|
```
|
|
|
|
storage.createBucket():
|
|
title: 'createBucket()'
|
|
$ref: '@supabase/storage-js."lib/StorageBucketApi".StorageBucketApi.createBucket'
|
|
notes: |
|
|
- Policy permissions required:
|
|
- `buckets` permissions: `insert`
|
|
- `objects` permissions: none
|
|
examples:
|
|
- name: Create bucket
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.storage
|
|
.createBucket('avatars', { public: false })
|
|
```
|
|
|
|
storage.emptyBucket():
|
|
title: 'emptyBucket()'
|
|
$ref: '@supabase/storage-js."lib/StorageBucketApi".StorageBucketApi.emptyBucket'
|
|
notes: |
|
|
- Policy permissions required:
|
|
- `buckets` permissions: `select`
|
|
- `objects` permissions: `select` and `delete`
|
|
examples:
|
|
- name: Empty bucket
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.storage
|
|
.emptyBucket('avatars')
|
|
```
|
|
storage.updateBucket():
|
|
title: 'updateBucket()'
|
|
$ref: '@supabase/storage-js."lib/StorageBucketApi".StorageBucketApi.updateBucket'
|
|
notes: |
|
|
- Policy permissions required:
|
|
- `buckets` permissions: `update`
|
|
- `objects` permissions: none
|
|
examples:
|
|
- name: Update bucket
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.storage
|
|
.updateBucket('avatars', { public: false })
|
|
```
|
|
|
|
storage.deleteBucket():
|
|
title: 'deleteBucket()'
|
|
$ref: '@supabase/storage-js."lib/StorageBucketApi".StorageBucketApi.deleteBucket'
|
|
notes: |
|
|
- Policy permissions required:
|
|
- `buckets` permissions: `select` and `delete`
|
|
- `objects` permissions: none
|
|
examples:
|
|
- name: Delete bucket
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.storage
|
|
.deleteBucket('avatars')
|
|
```
|
|
|
|
storage.from.upload():
|
|
title: 'from.upload()'
|
|
$ref: '@supabase/storage-js."lib/StorageFileApi".StorageFileApi.upload'
|
|
notes: |
|
|
- Policy permissions required:
|
|
- `buckets` permissions: none
|
|
- `objects` permissions: `insert`
|
|
- For React Native, using either `Blob`, `File` or `FormData` does not work as intended. Upload file using `ArrayBuffer` from base64 file data instead, see example below.
|
|
examples:
|
|
- name: Upload file
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const avatarFile = event.target.files[0]
|
|
const { data, error } = await supabase
|
|
.storage
|
|
.from('avatars')
|
|
.upload('public/avatar1.png', avatarFile, {
|
|
cacheControl: '3600',
|
|
upsert: false
|
|
})
|
|
```
|
|
- name: Upload file using `ArrayBuffer` from base64 file data
|
|
js: |
|
|
```js
|
|
import {decode} from 'base64-arraybuffer'
|
|
|
|
const { data, error } = await supabase
|
|
.storage
|
|
.from('avatars')
|
|
.upload('public/avatar1.png', decode('base64FileData'), {
|
|
contentType: 'image/png'
|
|
})
|
|
```
|
|
|
|
storage.from.update():
|
|
title: 'from.update()'
|
|
$ref: '@supabase/storage-js."lib/StorageFileApi".StorageFileApi.update'
|
|
notes: |
|
|
- Policy permissions required:
|
|
- `buckets` permissions: none
|
|
- `objects` permissions: `update` and `select`
|
|
- For React Native, using either `Blob`, `File` or `FormData` does not work as intended. Update file using `ArrayBuffer` from base64 file data instead, see example below.
|
|
examples:
|
|
- name: Update file
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const avatarFile = event.target.files[0]
|
|
const { data, error } = await supabase
|
|
.storage
|
|
.from('avatars')
|
|
.update('public/avatar1.png', avatarFile, {
|
|
cacheControl: '3600',
|
|
upsert: false
|
|
})
|
|
```
|
|
- name: Update file using `ArrayBuffer` from base64 file data
|
|
js: |
|
|
```js
|
|
import {decode} from 'base64-arraybuffer'
|
|
|
|
const { data, error } = await supabase
|
|
.storage
|
|
.from('avatars')
|
|
.update('public/avatar1.png', decode('base64FileData'), {
|
|
contentType: 'image/png'
|
|
})
|
|
```
|
|
|
|
storage.from.move():
|
|
title: 'from.move()'
|
|
$ref: '@supabase/storage-js."lib/StorageFileApi".StorageFileApi.move'
|
|
notes: |
|
|
- Policy permissions required:
|
|
- `buckets` permissions: none
|
|
- `objects` permissions: `update` and `select`
|
|
examples:
|
|
- name: Move file
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.storage
|
|
.from('avatars')
|
|
.move('public/avatar1.png', 'private/avatar2.png')
|
|
```
|
|
|
|
storage.from.createSignedUrl():
|
|
title: 'from.createSignedUrl()'
|
|
$ref: '@supabase/storage-js."lib/StorageFileApi".StorageFileApi.createSignedUrl'
|
|
notes: |
|
|
- Policy permissions required:
|
|
- `buckets` permissions: none
|
|
- `objects` permissions: `select`
|
|
examples:
|
|
- name: Create Signed URL
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { signedURL, error } = await supabase
|
|
.storage
|
|
.from('avatars')
|
|
.createSignedUrl('folder/avatar1.png', 60)
|
|
```
|
|
|
|
storage.from.getPublicUrl():
|
|
title: 'from.getPublicUrl()'
|
|
$ref: '@supabase/storage-js."lib/StorageFileApi".StorageFileApi.getPublicUrl'
|
|
notes: |
|
|
- Policy permissions required:
|
|
- `buckets` permissions: none
|
|
- `objects` permissions: none
|
|
examples:
|
|
- name: Returns the URL for an asset in a public bucket
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { publicURL, error } = supabase
|
|
.storage
|
|
.from('public-bucket')
|
|
.getPublicUrl('folder/avatar1.png')
|
|
```
|
|
|
|
storage.from.download():
|
|
title: 'from.download()'
|
|
$ref: '@supabase/storage-js."lib/StorageFileApi".StorageFileApi.download'
|
|
notes: |
|
|
- Policy permissions required:
|
|
- `buckets` permissions: none
|
|
- `objects` permissions: `select`
|
|
examples:
|
|
- name: Download file
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.storage
|
|
.from('avatars')
|
|
.download('folder/avatar1.png')
|
|
```
|
|
|
|
storage.from.remove():
|
|
title: 'from.remove()'
|
|
$ref: '@supabase/storage-js."lib/StorageFileApi".StorageFileApi.remove'
|
|
notes: |
|
|
- Policy permissions required:
|
|
- `buckets` permissions: none
|
|
- `objects` permissions: `delete` and `select`
|
|
examples:
|
|
- name: Delete file
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.storage
|
|
.from('avatars')
|
|
.remove(['folder/avatar1.png'])
|
|
```
|
|
|
|
storage.from.list():
|
|
title: 'from.list()'
|
|
$ref: '@supabase/storage-js."lib/StorageFileApi".StorageFileApi.list'
|
|
notes: |
|
|
- Policy permissions required:
|
|
- `buckets` permissions: none
|
|
- `objects` permissions: `select`
|
|
examples:
|
|
- name: List files in a bucket
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.storage
|
|
.from('avatars')
|
|
.list('folder', {
|
|
limit: 100,
|
|
offset: 0,
|
|
sortBy: { column: 'name', order: 'asc' },
|
|
})
|
|
```
|
|
|
|
Using Modifiers:
|
|
description: |
|
|
Modifiers can be used on `select()` queries.
|
|
|
|
If a Postgres function returns a table response, you can also apply modifiers to the `rpc()` function.
|
|
|
|
limit():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.limit'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.limit(1)
|
|
```
|
|
- name: With embedded resources
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.select('name, cities(name)')
|
|
.eq('name', 'United States')
|
|
.limit(1, { foreignTable: 'cities' })
|
|
```
|
|
|
|
order():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.order'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name', 'country_id')
|
|
.order('id', { ascending: false })
|
|
```
|
|
- name: With embedded resources
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.select('name, cities(name)')
|
|
.eq('name', 'United States')
|
|
.order('name', {foreignTable: 'cities'})
|
|
```
|
|
|
|
range():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.range'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.range(0,3)
|
|
```
|
|
|
|
single():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.single'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.single()
|
|
```
|
|
|
|
Using Filters:
|
|
description: |
|
|
Filters can be used on `select()`, `update()`, and `delete()` queries.
|
|
|
|
If a Postgres function returns a table response, you can also apply filters.
|
|
|
|
### Applying Filters
|
|
|
|
You must apply your filters to the end of your query. For example:
|
|
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.eq('name', 'The Shire') // Correct
|
|
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.eq('name', 'The Shire') // Incorrect
|
|
.select('name, country_id')
|
|
```
|
|
|
|
### Chaining
|
|
|
|
Filters can be chained together to produce advanced queries. For example:
|
|
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.gte('population', 1000)
|
|
.lt('population', 10000)
|
|
```
|
|
|
|
.filter():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.filter'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.filter('name', 'eq', 'Paris')
|
|
```
|
|
- name: With `update()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.update({ name: 'Mordor' })
|
|
.filter('name', 'eq', 'Paris')
|
|
```
|
|
- name: With `delete()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.delete()
|
|
.filter('name', 'eq', 'Paris')
|
|
```
|
|
- name: With `rpc()`
|
|
js: |
|
|
```js
|
|
// Only valid if the Postgres function returns a table type.
|
|
const { data, error } = await supabase
|
|
.rpc('echo_all_cities')
|
|
.filter('name', 'eq', 'Paris')
|
|
```
|
|
- name: Filter embedded resources
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, countries ( name )')
|
|
.filter('countries.name', 'eq', 'France')
|
|
```
|
|
|
|
.or():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.or'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.or('id.eq.20,id.eq.30')
|
|
```
|
|
- name: Use `or` with `and`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.or('id.gt.20,and(name.eq.New Zealand,name.eq.France)')
|
|
```
|
|
- name: Use `or` on foreign tables
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.select('id, cities(*)')
|
|
.or('name.eq.Wellington,name.eq.Paris', { foreignTable: "cities" })
|
|
```
|
|
|
|
.not():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.not'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.not('name', 'eq', 'Paris')
|
|
```
|
|
- name: With `update()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.update({ name: 'Mordor' })
|
|
.not('name', 'eq', 'Paris')
|
|
```
|
|
- name: With `delete()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.delete()
|
|
.not('name', 'eq', 'Paris')
|
|
```
|
|
- name: With `rpc()`
|
|
js: |
|
|
```js
|
|
// Only valid if the Postgres function returns a table type.
|
|
const { data, error } = await supabase
|
|
.rpc('echo_all_cities')
|
|
.not('name', 'eq', 'Paris')
|
|
```
|
|
|
|
.match():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.match'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.match({name: 'Beijing', country_id: 156})
|
|
```
|
|
- name: With `update()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.update({ name: 'Mordor' })
|
|
.match({name: 'Beijing', country_id: 156})
|
|
```
|
|
- name: With `delete()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.delete()
|
|
.match({name: 'Beijing', country_id: 156})
|
|
```
|
|
- name: With `rpc()`
|
|
js: |
|
|
```js
|
|
// Only valid if the Postgres function returns a table type.
|
|
const { data, error } = await supabase
|
|
.rpc('echo_all_cities')
|
|
.match({name: 'Beijing', country_id: 156})
|
|
```
|
|
|
|
.eq():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.eq'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.eq('name', 'The shire')
|
|
```
|
|
- name: With `update()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.update({ name: 'Mordor' })
|
|
.eq('name', 'San Francisco')
|
|
```
|
|
- name: With `delete()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.delete()
|
|
.eq('name', 'Mordor')
|
|
```
|
|
- name: With `rpc()`
|
|
js: |
|
|
```js
|
|
// Only valid if the Postgres function returns a table type.
|
|
const { data, error } = await supabase
|
|
.rpc('echo_all_cities')
|
|
.eq('name', 'San Francisco')
|
|
```
|
|
|
|
.neq():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.neq'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.neq('name', 'The shire')
|
|
```
|
|
- name: With `update()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.update({ name: 'Mordor' })
|
|
.neq('name', 'San Francisco')
|
|
```
|
|
- name: With `delete()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.delete()
|
|
.neq('name', 'Mordor')
|
|
```
|
|
- name: With `rpc()`
|
|
js: |
|
|
```js
|
|
// Only valid if the Postgres function returns a table type.
|
|
const { data, error } = await supabase
|
|
.rpc('echo_all_cities')
|
|
.neq('name', 'Lagos')
|
|
```
|
|
|
|
.gt():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.gt'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.gt('country_id', 250)
|
|
```
|
|
- name: With `update()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.update({ name: 'Mordor' })
|
|
.gt('country_id', 250)
|
|
```
|
|
- name: With `delete()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.delete()
|
|
.gt('country_id', 250)
|
|
```
|
|
- name: With `rpc()`
|
|
js: |
|
|
```js
|
|
// Only valid if the Postgres function returns a table type.
|
|
const { data, error } = await supabase
|
|
.rpc('echo_all_cities')
|
|
.gt('country_id', 250)
|
|
```
|
|
|
|
.gte():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.gte'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.gte('country_id', 250)
|
|
```
|
|
- name: With `update()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.update({ name: 'Mordor' })
|
|
.gte('country_id', 250)
|
|
```
|
|
- name: With `delete()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.delete()
|
|
.gte('country_id', 250)
|
|
```
|
|
- name: With `rpc()`
|
|
js: |
|
|
```js
|
|
// Only valid if the Postgres function returns a table type.
|
|
const { data, error } = await supabase
|
|
.rpc('echo_all_cities')
|
|
.gte('country_id', 250)
|
|
```
|
|
|
|
.lt():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.lt'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.lt('country_id', 250)
|
|
```
|
|
- name: With `update()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.update({ name: 'Mordor' })
|
|
.lt('country_id', 250)
|
|
```
|
|
- name: With `delete()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.delete()
|
|
.lt('country_id', 250)
|
|
```
|
|
- name: With `rpc()`
|
|
js: |
|
|
```js
|
|
// Only valid if the Postgres function returns a table type.
|
|
const { data, error } = await supabase
|
|
.rpc('echo_all_cities')
|
|
.lt('country_id', 250)
|
|
```
|
|
|
|
.lte():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.lte'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.lte('country_id', 250)
|
|
```
|
|
- name: With `update()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.update({ name: 'Mordor' })
|
|
.lte('country_id', 250)
|
|
```
|
|
- name: With `delete()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.delete()
|
|
.lte('country_id', 250)
|
|
```
|
|
- name: With `rpc()`
|
|
js: |
|
|
```js
|
|
// Only valid if the Postgres function returns a table type.
|
|
const { data, error } = await supabase
|
|
.rpc('echo_all_cities')
|
|
.lte('country_id', 250)
|
|
```
|
|
|
|
.like():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.like'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.like('name', '%la%')
|
|
```
|
|
- name: With `update()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.update({ name: 'Mordor' })
|
|
.like('name', '%la%')
|
|
```
|
|
- name: With `delete()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.delete()
|
|
.like('name', '%la%')
|
|
```
|
|
- name: With `rpc()`
|
|
js: |
|
|
```js
|
|
// Only valid if the Postgres function returns a table type.
|
|
const { data, error } = await supabase
|
|
.rpc('echo_all_cities')
|
|
.like('name', '%la%')
|
|
```
|
|
|
|
.ilike():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.ilike'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.ilike('name', '%la%')
|
|
```
|
|
- name: With `update()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.update({ name: 'Mordor' })
|
|
.ilike('name', '%la%')
|
|
```
|
|
- name: With `delete()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.delete()
|
|
.ilike('name', '%la%')
|
|
```
|
|
- name: With `rpc()`
|
|
js: |
|
|
```js
|
|
// Only valid if the Postgres function returns a table type.
|
|
const { data, error } = await supabase
|
|
.rpc('echo_all_cities')
|
|
.ilike('name', '%la%')
|
|
```
|
|
|
|
.is():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.is'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.is('name', null)
|
|
```
|
|
- name: With `update()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.update({ name: 'Mordor' })
|
|
.is('name', null)
|
|
```
|
|
- name: With `delete()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.delete()
|
|
.is('name', null)
|
|
```
|
|
- name: With `rpc()`
|
|
js: |
|
|
```js
|
|
// Only valid if the Postgres function returns a table type.
|
|
const { data, error } = await supabase
|
|
.rpc('echo_all_cities')
|
|
.is('name', null)
|
|
```
|
|
|
|
.in():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.in'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.in('name', ['Rio de Janeiro', 'San Francisco'])
|
|
```
|
|
- name: With `update()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.update({ name: 'Mordor' })
|
|
.in('name', ['Rio de Janeiro', 'San Francisco'])
|
|
```
|
|
- name: With `delete()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.delete()
|
|
.in('name', ['Rio de Janeiro', 'San Francisco'])
|
|
```
|
|
- name: With `rpc()`
|
|
js: |
|
|
```js
|
|
// Only valid if the Postgres function returns a table type.
|
|
const { data, error } = await supabase
|
|
.rpc('echo_all_cities')
|
|
.in('name', ['Rio de Janeiro', 'San Francisco'])
|
|
```
|
|
|
|
.contains():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.cs'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.select('name, id, main_exports')
|
|
.contains('main_exports', ['oil'])
|
|
```
|
|
- name: With `update()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.update({ name: 'Mordor' })
|
|
.contains('main_exports', ['oil'])
|
|
```
|
|
- name: With `delete()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.delete()
|
|
.contains('main_exports', ['oil'])
|
|
```
|
|
- name: With `rpc()`
|
|
js: |
|
|
```js
|
|
// Only valid if the Postgres function returns a table type.
|
|
const { data, error } = await supabase
|
|
.rpc('echo_all_countries')
|
|
.contains('main_exports', ['oil'])
|
|
```
|
|
|
|
.containedBy():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.cd'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.select('name, id, main_exports')
|
|
.containedBy('main_exports', ['cars', 'food', 'machine'])
|
|
```
|
|
- name: With `update()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.update({ name: 'Mordor' })
|
|
.containedBy('main_exports', ['orks', 'surveillance', 'evil'])
|
|
```
|
|
- name: With `delete()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.delete()
|
|
.containedBy('main_exports', ['cars', 'food', 'machine'])
|
|
```
|
|
- name: With `rpc()`
|
|
js: |
|
|
```js
|
|
// Only valid if the Postgres function returns a table type.
|
|
const { data, error } = await supabase
|
|
.rpc('echo_all_countries')
|
|
.containedBy('main_exports', ['cars', 'food', 'machine'])
|
|
```
|
|
|
|
.rangeLt():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.sl'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.select('name, id, population_range_millions')
|
|
.rangeLt('population_range_millions', [150, 250])
|
|
```
|
|
- name: With `update()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.update({ name: 'Mordor' })
|
|
.rangeLt('population_range_millions', [150, 250])
|
|
```
|
|
- name: With `delete()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.delete()
|
|
.rangeLt('population_range_millions', [150, 250])
|
|
```
|
|
- name: With `rpc()`
|
|
js: |
|
|
```js
|
|
// Only valid if the Postgres function returns a table type.
|
|
const { data, error } = await supabase
|
|
.rpc('echo_all_countries')
|
|
.rangeLt('population_range_millions', [150, 250])
|
|
```
|
|
|
|
.rangeGt():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.sr'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.select('name, id, population_range_millions')
|
|
.rangeGt('population_range_millions', [150, 250])
|
|
```
|
|
- name: With `update()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.update({ name: 'Mordor' })
|
|
.rangeGt('population_range_millions', [150, 250])
|
|
```
|
|
- name: With `delete()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.delete()
|
|
.rangeGt('population_range_millions', [150, 250])
|
|
```
|
|
- name: With `rpc()`
|
|
js: |
|
|
```js
|
|
// Only valid if the Postgres function returns a table type.
|
|
const { data, error } = await supabase
|
|
.rpc('echo_all_countries')
|
|
.rangeGt('population_range_millions', [150, 250])
|
|
```
|
|
|
|
.rangeGte():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.nxl'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.select('name, id, population_range_millions')
|
|
.rangeGte('population_range_millions', [150, 250])
|
|
```
|
|
- name: With `update()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.update({ name: 'Mordor' })
|
|
.rangeGte('population_range_millions', [150, 250])
|
|
```
|
|
- name: With `delete()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.delete()
|
|
.rangeGte('population_range_millions', [150, 250])
|
|
```
|
|
- name: With `rpc()`
|
|
js: |
|
|
```js
|
|
// Only valid if the Postgres function returns a table type.
|
|
const { data, error } = await supabase
|
|
.rpc('echo_all_countries')
|
|
.rangeGte('population_range_millions', [150, 250])
|
|
```
|
|
|
|
.rangeLte():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.nxr'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.select('name, id, population_range_millions')
|
|
.rangeLte('population_range_millions', [150, 250])
|
|
```
|
|
- name: With `update()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.update({ name: 'Mordor' })
|
|
.rangeLte('population_range_millions', [150, 250])
|
|
```
|
|
- name: With `delete()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.delete()
|
|
.rangeLte('population_range_millions', [150, 250])
|
|
```
|
|
- name: With `rpc()`
|
|
js: |
|
|
```js
|
|
// Only valid if the Postgres function returns a table type.
|
|
const { data, error } = await supabase
|
|
.rpc('echo_all_countries')
|
|
.rangeLte('population_range_millions', [150, 250])
|
|
```
|
|
|
|
.rangeAdjacent():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.adj'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.select('name, id, population_range_millions')
|
|
.rangeAdjacent('population_range_millions', [70, 185])
|
|
```
|
|
- name: With `update()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.update({ name: 'Mordor' })
|
|
.rangeAdjacent('population_range_millions', [70, 185])
|
|
```
|
|
- name: With `delete()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.delete()
|
|
.rangeAdjacent('population_range_millions', [70, 185])
|
|
```
|
|
- name: With `rpc()`
|
|
js: |
|
|
```js
|
|
// Only valid if the Postgres function returns a table type.
|
|
const { data, error } = await supabase
|
|
.rpc('echo_all_countries')
|
|
.rangeAdjacent('population_range_millions', [70, 185])
|
|
```
|
|
|
|
.overlaps():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.ov'
|
|
examples:
|
|
- name: With `select()`
|
|
isSpotlight: true
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.select('name, id, main_exports')
|
|
.overlaps('main_exports', ['computers', 'minerals'])
|
|
```
|
|
- name: With `update()`
|
|
js: |
|
|
```js
|
|
let countries = await supabase
|
|
.from('countries')
|
|
.update({ name: 'Mordor' })
|
|
.overlaps('main_exports', ['computers', 'minerals'])
|
|
```
|
|
- name: With `delete()`
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.delete()
|
|
.overlaps('main_exports', ['computers', 'minerals'])
|
|
```
|
|
- name: With `rpc()`
|
|
js: |
|
|
```js
|
|
// Only valid if the Postgres function returns a table type.
|
|
const { data, error } = await supabase
|
|
.rpc('echo_all_countries')
|
|
.overlaps('main_exports', ['computers', 'minerals'])
|
|
```
|
|
|
|
.textSearch():
|
|
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.fts'
|
|
examples:
|
|
- name: Text search
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('quotes')
|
|
.select('catchphrase')
|
|
.textSearch('catchphrase', `'fat' & 'cat'`, {
|
|
config: 'english'
|
|
})
|
|
```
|
|
- name: Basic normalization
|
|
description: Uses PostgreSQL's `plainto_tsquery` function.
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('quotes')
|
|
.select('catchphrase')
|
|
.textSearch('catchphrase', `'fat' & 'cat'`, {
|
|
type: 'plain',
|
|
config: 'english'
|
|
})
|
|
```
|
|
- name: Full normalization
|
|
description: Uses PostgreSQL's `phraseto_tsquery` function.
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('quotes')
|
|
.select('catchphrase')
|
|
.textSearch('catchphrase', `'fat' & 'cat'`, {
|
|
type: 'phrase',
|
|
config: 'english'
|
|
})
|
|
```
|
|
- name: Full normalization
|
|
description: |
|
|
Uses PostgreSQL's `websearch_to_tsquery` function.
|
|
This function will never raise syntax errors, which makes it possible to use raw user-supplied input for search, and can be used
|
|
with advanced operators.
|
|
|
|
- `unquoted text`: text not inside quote marks will be converted to terms separated by & operators, as if processed by plainto_tsquery.
|
|
- `"quoted text"`: text inside quote marks will be converted to terms separated by <-> operators, as if processed by phraseto_tsquery.
|
|
- `OR`: the word “or” will be converted to the | operator.
|
|
- `-`: a dash will be converted to the ! operator.
|
|
|
|
js: |
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('quotes')
|
|
.select('catchphrase')
|
|
.textSearch('catchphrase', `'fat or cat'`, {
|
|
type: 'websearch',
|
|
config: 'english'
|
|
})
|
|
```
|