diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts new file mode 100644 index 00000000000..38ef02e1244 --- /dev/null +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts @@ -0,0 +1,435 @@ +// import SupabaseJsV1Nav from 'data/nav/supabase-js/v1' +// import SupabaseJsV2Nav from 'data/nav/supabase-js/v2' +// import SupabaseDartV0Nav from 'data/nav/supabase-dart/v0' +// import SupabaseDartV1Nav from 'data/nav/supabase-dart/v1' +// import SupabaseCLINav from 'data/nav/supabase-cli' +// import SupabaseAPINav from 'data/nav/supabase-api' +// import AuthServerNav from 'data/nav/auth-server' +// import StorageServerNav from 'data/nav/storage-server' + +import { NavMenu, References } from '../Navigation.types' + +export const REFERENCES: References = { + javascript: { + name: 'supabase-js', + library: 'supabase-js', + versions: ['v2', 'v1'], + icon: '/docs/img/libraries/javascript-icon.svg', + }, + dart: { + name: 'Flutter', + library: 'supabase-dart', + versions: ['v1', 'v0'], + icon: '/docs/img/libraries/flutter-icon.svg', + }, + cli: { + name: 'CLI', + library: undefined, + versions: [], + icon: '/docs/img/icons/cli-icon.svg', + }, + api: { + name: 'API', + library: undefined, + versions: [], + icon: '/docs/img/icons/api-icon.svg', + }, +} + +export const gettingstarted = { + label: 'Overview', + items: [ + { name: 'Introduction', url: '/', items: [] }, + { name: 'Features', url: '/features', items: [] }, + { name: 'Architecture', url: '/architecture', items: [] }, + ], +} + +export const tutorials = { + label: 'Quickstarts', + items: [ + { name: 'Angular', url: '/guides/with-angular', items: [] }, + { name: 'Expo', url: '/guides/with-expo', items: [] }, + { name: 'Flutter', url: '/guides/with-flutter', items: [] }, + { name: 'Ionic Angular', url: '/guides/with-ionic-angular', items: [] }, + { name: 'Ionic React', url: '/guides/with-ionic-react', items: [] }, + { name: 'Ionic Vue', url: '/guides/with-ionic-vue', items: [] }, + { name: 'Next.js', url: '/guides/with-nextjs', items: [] }, + { name: 'Nuxt 3', url: '/guides/with-nuxt-3', items: [] }, + { name: 'React', url: '/guides/with-react', items: [] }, + { name: 'RedwoodJS', url: '/guides/with-redwoodjs', items: [] }, + { name: 'SolidJS', url: '/guides/with-solidjs', items: [] }, + { name: 'Svelte', url: '/guides/with-svelte', items: [] }, + { name: 'SvelteKit', url: '/guides/with-sveltekit', items: [] }, + { name: 'Vue 3', url: '/guides/with-vue-3', items: [] }, + ], +} +export const cli = { + label: 'CLI', + items: [ + { name: 'Overview', url: '/guides/cli', items: [] }, + { name: 'Local Development', url: '/guides/cli/local-development', items: [] }, + { name: 'Managing Environments', url: '/guides/cli/managing-environments', items: [] }, + ], +} + +export const auth = { + label: 'Auth', + extras: [ + { name: 'API Reference', level: 'integrations', items: [] }, + { name: 'Integrations', level: 'reference', items: [] }, + ], + items: [ + { + name: 'Authentication', + url: undefined, + items: [ + { name: 'Login with Email', url: '/guides/auth/auth-email', items: [] }, + { name: 'Login with Magic Link', url: '/guides/auth/auth-magic-link', items: [] }, + { name: 'Login with Apple', url: '/guides/auth/auth-apple', items: [] }, + { name: 'Login with Azure', url: '/guides/auth/auth-azure', items: [] }, + { name: 'Login with Bitbucket', url: '/guides/auth/auth-bitbucket', items: [] }, + { name: 'Login with Discord', url: '/guides/auth/auth-discord', items: [] }, + { name: 'Login with Facebook', url: '/guides/auth/auth-facebook', items: [] }, + { name: 'Login with Github', url: '/guides/auth/auth-github', items: [] }, + { name: 'Login with Gitlab', url: '/guides/auth/auth-gitlab', items: [] }, + { name: 'Login with Google', url: '/guides/auth/auth-google', items: [] }, + { name: 'Login with Keycloak', url: '/guides/auth/auth-keycloak', items: [] }, + { name: 'Login with LinkedIn', url: '/guides/auth/auth-linkedin', items: [] }, + { name: 'Login with Notion', url: '/guides/auth/auth-notion', items: [] }, + { name: 'Login with Slack', url: '/guides/auth/auth-slack', items: [] }, + { name: 'Login with Spotify', url: '/guides/auth/auth-spotify', items: [] }, + { name: 'Login with Twitch', url: '/guides/auth/auth-twitch', items: [] }, + { name: 'Login with Twitter', url: '/guides/auth/auth-twitter', items: [] }, + { name: 'Login with WorkOS', url: '/guides/auth/auth-workos', items: [] }, + { name: 'Phone Auth with Twilio', url: '/guides/auth/auth-twilio', items: [] }, + { name: 'Phone Auth with Vonage', url: '/guides/auth/auth-vonage', items: [] }, + { + name: 'Phone Auth with MessageBird', + url: '/guides/auth/auth-messagebird', + items: [], + }, + ], + }, + { + name: 'Authorization', + url: undefined, + items: [ + { name: 'Row Level Security', url: '/guides/auth/row-level-security', items: [] }, + { name: 'Managing User Data', url: '/guides/auth/managing-user-data', items: [] }, + { name: 'Enable Captcha Protection', url: '/guides/auth/auth-captcha', items: [] }, + { name: 'Server-side Rendering', url: '/guides/auth/server-side-rendering', items: [] }, + { name: 'Multi-Factor Authentication', url: '/guides/auth/auth-mfa', items: [] }, + ], + }, + { + name: 'Auth Helpers', + url: undefined, + items: [ + { name: 'Overview', url: '/guides/auth/auth-helpers', items: [] }, + { name: 'Auth UI', url: '/guides/auth/auth-helpers/auth-ui', items: [] }, + { name: 'Next.js', url: '/guides/auth/auth-helpers/nextjs', items: [] }, + { name: 'SvelteKit', url: '/guides/auth/auth-helpers/sveltekit', items: [] }, + { name: 'Remix', url: '/guides/auth/auth-helpers/remix', items: [] }, + ], + }, + { + name: 'Deep Dive', + url: undefined, + items: [ + { + name: 'Part One: JWTs', + url: '/learn/auth-deep-dive/auth-deep-dive-jwts', + items: [], + }, + { + name: 'Part Two: Row Level Security', + url: '/learn/auth-deep-dive/auth-row-level-security', + items: [], + }, + { name: 'Part Three: Policies', url: '/learn/auth-deep-dive/auth-policies', items: [] }, + { name: 'Part Four: GoTrue', url: '/learn/auth-deep-dive/auth-gotrue', items: [] }, + { + name: 'Part Five: Google OAuth', + url: '/learn/auth-deep-dive/auth-google-oauth', + items: [], + }, + ], + }, + ], +} + +export const database = { + label: 'Database', + items: [ + { name: 'Overview', url: '/guides/database', items: [] }, + { name: 'Database Connections', url: '/guides/database/connecting-to-postgres', items: [] }, + { name: 'Tables and Data', url: '/guides/database/tables', items: [] }, + { name: 'Database Functions', url: '/guides/database/functions', items: [] }, + { name: 'Database Webhooks', url: '/guides/database/database-webhooks', items: [] }, + { name: 'Full Text Search', url: '/guides/database/full-text-search', items: [] }, + { name: 'Database Testing', url: '/guides/database/testing', items: [] }, + { + name: 'Serverless APIs', + url: undefined, + items: [ + { name: 'Overview', url: '/guides/api', items: [] }, + { name: 'Generating Types', url: '/guides/api/generating-types', items: [] }, + ], + }, + { + name: 'Extensions', + url: undefined, + items: [ + { name: 'Overview', url: '/guides/database/extensions', items: [] }, + { + name: 'plv8: Javascript Language', + url: '/guides/database/extensions/plv8', + items: [], + }, + { name: 'http: RESTful Client', url: '/guides/database/extensions/http', items: [] }, + { + name: 'pg_cron: Job Scheduling', + url: '/guides/database/extensions/pgcron', + items: [], + }, + { + name: 'pg_net: Async Networking', + url: '/guides/database/extensions/pgnet', + items: [], + }, + { name: 'pgTAP: Unit Testing', url: '/guides/database/extensions/pgtap', items: [] }, + { + name: 'uuid-ossp: Unique Identifiers', + url: '/guides/database/extensions/uuid-ossp', + items: [], + }, + ], + }, + { + name: 'Configuration', + url: undefined, + items: [ + { name: 'Timeouts', url: '/guides/database/timeouts', items: [] }, + { name: 'Replication', url: '/guides/database/replication', items: [] }, + { name: 'Passwords', url: '/guides/database/managing-passwords', items: [] }, + { name: 'Timezones', url: '/guides/database/managing-timezones', items: [] }, + ], + }, + ], +} + +export const functions = { + label: 'Edge Functions', + items: [ + { name: 'Overview', url: '/guides/functions', items: [] }, + { name: 'Auth', url: '/guides/functions/auth', items: [] }, + { name: 'Examples', url: '/guides/functions/examples', items: [] }, + { name: 'CI/CD Workflow', url: '/guides/functions/cicd-workflow', items: [] }, + ], +} + +export const realtime = { + label: 'Realtime', + items: [ + { name: 'Overview', url: '/guides/realtime', items: [] }, + { name: 'Quickstart', url: '/guides/realtime/quickstart', items: [] }, + { name: 'Postgres CDC', url: '/guides/realtime/postgres-cdc', items: [] }, + { name: 'Rate Limits', url: '/guides/realtime/rate-limits', items: [] }, + ], +} + +export const storage = { + label: 'Storage', + items: [ + { name: 'Overview', url: '/guides/storage', items: [] }, + { name: 'CDN', url: '/guides/storage-cdn', items: [] }, + ], +} + +export const platform = { + label: 'Platform', + items: [ + { name: 'Overview', url: '/guides/hosting/platform', items: [] }, + { name: 'Custom Domains', url: '/guides/platform/custom-domains', items: [] }, + { name: 'Database Usage', url: '/guides/platform/database-usage', items: [] }, + { name: 'Logging', url: '/guides/platform/logs', items: [] }, + { name: 'Metrics', url: '/guides/platform/metrics', items: [] }, + { + name: 'Migrating and upgrading', + url: '/guides/platform/migrating-and-upgrading-projects', + items: [], + }, + { name: 'Performance Tuning', url: '/guides/platform/performance', items: [] }, + { name: 'Permissions', url: '/guides/platform/permissions', items: [] }, + { name: 'Production Readiness', url: '/guides/platform/going-into-prod', items: [] }, + ], +} + +export const selfHosting = { + label: 'Self Hosting', + items: [ + { name: 'Overview', url: '/guides/hosting/overview', items: [] }, + { name: 'Docker', url: '/guides/hosting/docker', items: [] }, + ], +} + +export const migrate = { + label: 'Migrate to Supabase', + items: [ + { name: 'Firebase Auth', url: '/guides/migrations/firebase-auth', items: [] }, + { name: 'Firestore Data', url: '/guides/migrations/firestore-data', items: [] }, + { name: 'Firebase Storage', url: '/guides/migrations/firebase-storage', items: [] }, + { name: 'Heroku', url: '/guides/migrations/heroku', items: [] }, + ], +} + +export const integrations = { + label: 'Integrations', + items: [ + { name: 'Supabase Marketplace', url: '/guides/integrations/integrations', items: [] }, + { + name: 'Auth', + url: undefined, + items: [ + { name: 'Auth0', url: '/guides/integrations/auth0', items: [] }, + { name: 'Authsignal', url: '/guides/integrations/authsignal', items: [] }, + { name: 'Clerk', url: '/guides/integrations/clerk', items: [] }, + { name: 'keyri', url: '/guides/integrations/keyri', items: [] }, + { name: 'Stytch', url: '/guides/integrations/stytch', items: [] }, + { name: 'SuperTokens', url: '/guides/integrations/supertokens', items: [] }, + ], + }, + { + name: 'Caching / Offline-first', + url: undefined, + items: [{ name: 'Polyscale', url: '/guides/integrations/polyscale', items: [] }], + }, + { + name: 'Developer Tools', + url: undefined, + items: [ + { name: 'pgMustard', url: '/guides/integrations/pgmustard', items: [] }, + { name: 'Prisma', url: '/guides/integrations/prisma', items: [] }, + { name: 'Sequin', url: '/guides/integrations/sequin', items: [] }, + { name: 'Snaplet', url: '/guides/integrations/snaplet', items: [] }, + { name: 'Vercel', url: '/guides/integrations/vercel', items: [] }, + ], + }, + { + name: 'Low-code', + url: undefined, + items: [ + { name: 'Appsmith', url: '/guides/integrations/appsmith', items: [] }, + { name: 'Dashibase', url: '/guides/integrations/dashibase', items: [] }, + { name: 'DhiWise', url: '/guides/integrations/dhiwise', items: [] }, + { name: 'Directus', url: '/guides/integrations/directus', items: [] }, + { name: 'Draftbit', url: '/guides/integrations/draftbit', items: [] }, + { name: 'Plasmic', url: '/guides/integrations/plasmic', items: [] }, + ], + }, + ], +} + +export const reference = { + items: [ + { + name: 'Client libraries', + items: [ + { + name: 'supabase-js', + href: '/reference/javascript/start', + level: 'reference_javascript', + items: [], + icon: '/img/icons/javascript.svg', + }, + { + name: 'supabase-dart', + href: '/reference/dart/start', + level: 'reference_dart', + items: [], + icon: '/img/icons/javascript.svg', + }, + { + name: 'supbase-python', + href: '/reference/python/start', + level: 'reference_python', + items: [], + icon: '/img/icons/javascript.svg', + }, + ], + }, + { + name: 'Other tools', + items: [ + { + name: 'Supabase CLI', + href: '/reference/cli', + items: [], + icon: '/img/icons/javascript.svg', + }, + { + name: 'Management API', + href: '/reference/javascript', + items: [], + icon: '/img/icons/javascript.svg', + }, + ], + }, + ], +} + +export const reference_javascript = { + icon: '/img/icons/javascript-icon.svg', + title: 'javascript-js', + parent: '/reference', + items: [ + { + name: 'Getting Started', + items: [ + { + name: 'fake link', + href: '/reference/javascript/start', + level: 'reference_javascript', + items: [], + icon: '/img/icons/javascript.svg', + }, + ], + }, + ], +} + +// export const reference: [ +// { +// label: 'Official' +// items: [ +// { name: 'Reference Documentation'; url: '/reference'; items: [] }, +// { name: 'Supabase JavaScript Library'; url: '/reference/javascript'; items: [] }, +// { name: 'Supabase Flutter Library'; url: '/reference/dart'; items: [] }, +// { name: 'Supabase CLI'; url: '/reference/cli'; items: [] }, +// { name: 'Management API'; url: '/reference/api'; items: [] } +// ] +// }, +// { +// label: 'Self-hosting' +// items: [ +// { name: 'Auth Server'; url: '/reference/auth'; items: [] }, +// { name: 'Storage Server'; url: '/reference/storage'; items: [] } +// ] +// } +// { +// label: 'Clients', +// items: [ +// { name: 'Auth Server', url: '/reference/auth', items: [] }, +// { name: 'Storage Server', url: '/reference/storage', items: [] }, +// ], +// }, +// 'reference/javascript': SupabaseJsV2Nav, +// 'reference/javascript/v1': SupabaseJsV1Nav, +// 'reference/dart': SupabaseDartV1Nav, +// 'reference/dart/v0': SupabaseDartV0Nav, +// 'reference/cli': SupabaseCLINav, +// 'reference/api': SupabaseAPINav, +// 'reference/auth': AuthServerNav, +// 'reference/storage': StorageServerNav, +// ] diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx new file mode 100644 index 00000000000..3914684bdeb --- /dev/null +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx @@ -0,0 +1,382 @@ +import { useRouter } from 'next/router' +import { useState, useEffect } from 'react' +import { IconChevronLeft } from '~/../../packages/ui' +import * as NavItems from './NavigationMenu.constants' +import NavigationMenuGuideList from './NavigationMenuGuideList' + +const SideNav = () => { + console.log('sidebar rerendered') + const router = useRouter() + + const [level, setLevel] = useState('home') + + const tempBasePath = '/new' + + useEffect(() => { + function handleRouteChange(url: string) { + console.log('path changed') + console.log(url) + switch (url) { + case `/docs${tempBasePath}`: + setLevel('home') + break + case `/docs${tempBasePath}/database`: + setLevel('database') + break + case `/docs${tempBasePath}/auth`: + setLevel('auth') + break + case `/docs${tempBasePath}/storage`: + setLevel('storage') + break + case `/docs${tempBasePath}/realtime`: + setLevel('realtime') + break + case `/docs${tempBasePath}/edge-functions`: + setLevel('functions') + break + case `/docs${tempBasePath}/reference`: + setLevel('reference') + break + case `/docs${tempBasePath}/integrations`: + setLevel('integrations') + break + case `/docs${tempBasePath}/platform`: + setLevel('platform') + break + case url.includes(`/docs${tempBasePath}/reference/javascript/`) && url: + setLevel('reference_javascript') + break + + default: + break + } + } + + // Listen for page changes after a navigation or when the query changes + router.events.on('routeChangeComplete', handleRouteChange) + return () => { + router.events.off('routeChangeComplete', handleRouteChange) + } + }, [router.events]) + + const home = [ + [ + { + label: 'Home', + icon: 'home.svg', + href: '', + level: 'home', + }, + { + label: 'Getting started', + icon: 'gettingstarted.svg', + href: '/getting-started', + level: 'gettingstarted', + }, + { + label: 'Tutorials', + icon: 'tutorials.svg', + href: '/tutorials', + level: 'tutorials', + }, + ], + [ + { + label: 'Database', + icon: 'database.svg', + href: '/database', + level: 'database', + }, + { + label: 'Auth', + icon: 'auth.svg', + href: '/auth', + level: 'auth', + }, + { + label: 'Storage', + icon: 'storage.svg', + href: '/storage', + level: 'storage', + }, + { + label: 'Realtime', + icon: 'realtime.svg', + href: '/realtime', + level: 'realtime', + }, + { + label: 'Edge Functions', + icon: 'functions.svg', + href: '/edge-functions', + level: 'functions', + }, + ], + [ + { + label: 'API Reference', + icon: 'reference.svg', + href: '/reference', + level: 'reference', + }, + { + label: 'Integrations', + icon: 'integrations.svg', + href: '/integrations', + level: 'integrations', + }, + { + label: 'Platform', + icon: 'platform.svg', + href: '/platform', + level: 'platform', + }, + ], + ] + + const auth = [ + { + label: 'back', + icon: 'home.svg', + href: '', + level: 'home', + }, + ] + + const ref = [ + { + label: 'back', + icon: 'home.svg', + href: '', + level: 'home', + }, + { + label: 'supabase-js v2', + icon: 'home.svg', + href: '/reference/javascript/start', + level: 'ref_js', + }, + { + label: 'supabase-js v1', + icon: 'home.svg', + href: '/reference/javascript/v1/start', + level: 'ref_js', + }, + { + label: 'supabase-dart v1', + icon: 'home.svg', + href: '/reference/dart/start', + level: 'ref_dart', + }, + ] + + const ref_js = [ + { + label: 'back to ref', + icon: 'home.svg', + href: '/reference', + level: 'ref', + }, + ] + + return ( +
+ {/* // main menu */} +
+ +
+ + + + + + + + + + + + + {/* reference level */} + + + {/* // ref menu */} + {/*
+
    + {ref.map((link) => { + return ( +
  • { + setLevel(link.level) + router.push(tempBasePath + link.href) + }} + className={[ + 'flex items-center gap-3', + 'text-base transition-all duration-200 text-scale-1200 hover:text-brand-900 hover:cursor-pointer ', + ].join(' ')} + > + + {link.label} +
  • + ) + })} +
+
*/} + + {/* // JS menu */} + {/*
+
    + {ref_js.map((link) => { + return ( +
  • { + setLevel(link.level) + router.push(tempBasePath + link.href) + }} + className={[ + 'flex items-center gap-3', + 'text-base transition-all duration-200 text-scale-1200 hover:text-brand-900 hover:cursor-pointer ', + ].join(' ')} + > + + {link.label} +
  • + ) + })} +
+
*/} + + {/* // Dart menu */} + {/*
+
    + {ref_js.map((link) => { + return ( +
  • { + setLevel(link.level) + router.push(tempBasePath + link.href) + }} + className={[ + 'flex items-center gap-3', + 'text-base transition-all duration-200 text-scale-1200 hover:text-brand-900 hover:cursor-pointer ', + ].join(' ')} + > + + {link.label} +
  • + ) + })} +
+
*/} +
+ ) +} + +export default SideNav diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuGuideList.tsx b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuGuideList.tsx new file mode 100644 index 00000000000..553b3a71999 --- /dev/null +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuGuideList.tsx @@ -0,0 +1,117 @@ +import { useRouter } from 'next/router' +import rehypeFilter from 'react-markdown/lib/rehype-filter' +import { IconChevronLeft } from '~/../../packages/ui' +import * as NavItems from './NavigationMenu.constants' + +const NavigationMenuGuideList = ({ currentLevel, setLevel, tempBasePath, id }) => { + const router = useRouter() + + const menu = NavItems[id] + + return ( +
+ +
+ ) +} + +export default NavigationMenuGuideList diff --git a/apps/docs/components/NavigationMenu/index.tsx b/apps/docs/components/NavigationMenu/index.tsx deleted file mode 100644 index 6dfc16fd784..00000000000 --- a/apps/docs/components/NavigationMenu/index.tsx +++ /dev/null @@ -1,216 +0,0 @@ -import { useRouter } from 'next/router' -import { useState } from 'react' - -const SideNav = () => { - console.log('sidebar rerendered') - const router = useRouter() - - const [level, setLevel] = useState('home') - - const tempBasePath = '/new' - - const home = [ - { - label: 'Home', - icon: 'home.svg', - href: '', - level: 'home', - }, - { - label: 'Getting started', - icon: 'getting-started.svg', - level: 'getting-started', - }, - { - label: 'Tutorials', - icon: 'tutorials.svg', - level: 'tutorials', - }, - { - label: 'Database', - icon: 'database.svg', - level: 'database', - }, - { - label: 'Auth', - icon: 'auth.svg', - href: '/auth', - level: 'auth', - }, - { - label: 'Storage', - icon: 'storage.svg', - level: 'storage', - }, - { - label: 'API Reference', - icon: 'api.svg', - href: '/ref', - level: 'ref', - }, - { - label: 'Integrations', - icon: 'integrations.svg', - level: 'integrations', - }, - { - label: 'Platform', - icon: 'platform.svg', - level: 'platform', - }, - ] - - const auth = [ - { - label: 'back', - icon: 'home.svg', - href: '', - level: 'home', - }, - ] - - const ref = [ - { - label: 'back', - icon: 'home.svg', - href: '', - level: 'home', - }, - { - label: 'supabsae-js', - icon: 'home.svg', - href: '/ref/js/start', - level: 'ref_js', - }, - ] - - const ref_js = [ - { - label: 'back to ref', - icon: 'home.svg', - href: '/ref', - level: 'ref', - }, - ] - - return ( -
- {/* // main menu */} -
- -
- - {/* // auth menu */} -
- -
- - {/* // ref menu */} -
- -
- - {/* // JS menu */} -
- -
-
- ) -} - -export default SideNav diff --git a/apps/docs/layouts/SiteLayout.tsx b/apps/docs/layouts/SiteLayout.tsx index f47a65e37c0..aaff2611a13 100644 --- a/apps/docs/layouts/SiteLayout.tsx +++ b/apps/docs/layouts/SiteLayout.tsx @@ -1,11 +1,17 @@ +import { useRouter } from 'next/router' import Footer from '~/components/Footer' import NavBar from '~/components/Navigation/NavBar' -import NavigationMenu from '~/components/NavigationMenu' +import NavigationMenu from '~/components/Navigation/NavigationMenu/NavigationMenu' const Layout = ({ children }) => { + const router = useRouter() return ( <>
+
diff --git a/apps/docs/pages/new/reference/dart/[...slug].tsx b/apps/docs/pages/new/reference/dart/[...slug].tsx new file mode 100644 index 00000000000..23c4092bc51 --- /dev/null +++ b/apps/docs/pages/new/reference/dart/[...slug].tsx @@ -0,0 +1,381 @@ +import { + useEffect, + // useRef, + useState, +} from 'react' +// pages/index.js + +import fs from 'fs' + +import matter from 'gray-matter' +import { MDXRemote } from 'next-mdx-remote' +import { serialize } from 'next-mdx-remote/serialize' +import remarkGfm from 'remark-gfm' +import components from '~/components/index' +import { getAllDocs } from '~/lib/docs' + +import ReactMarkdown from 'react-markdown' + +// @ts-ignore +import jsTypeSpec from '~/../../spec/enrichments/tsdoc_v2/combined.json' +// @ts-ignore +import examples from '~/../../spec/examples/examples.yml' assert { type: 'yml' } +// @ts-expect-error +import jsSpec from '~/../../spec/supabase_dart_v1_temp_new_shape.yml' assert { type: 'yml' } + +import { IconDatabase, Tabs } from 'ui' +import CodeBlock from '~/components/CodeBlock/CodeBlock' + +import { useRouter } from 'next/router' +import { extractTsDocNode, generateParameters } from '~/lib/refGenerator/helpers' + +const marginTop = 256 +export default function Ref(props) { + // const myRef = useRef(null) + + console.log('props', props) + + const [offsetY, setOffsetY] = useState(0) + const [sections, setSections] = useState([]) + + // useEffect(() => { + // window.scrollTo(0, 0) + // setOffsetY(0) + // }, []) + + useEffect(() => { + const els: HTMLElement[] = Array.from(document.querySelectorAll('div.ref-container')) + + const allSections = els.map((el: HTMLElement, index: number) => { + const { top: boundingTop } = el.getBoundingClientRect() + + return { + topic: el.getAttribute('id')!, + boundingTop, + isActive: index === 0, + } + }) + + // console.log('allSections', allSections) + setSections(allSections) + }, []) + + // useEffect(() => { + // if (sections.length <= 1) return + + // const onScroll = () => { + // console.log('SCROLL EVENT') + // setOffsetY(window.pageYOffset) + // } + // window.addEventListener('scroll', debounce(onScroll, 500)) + + // return () => window.removeEventListener('scroll', onScroll) + // }, [sections]) + + // useEffect(() => { + // if (sections.length === 0) return + + // if (sections.length === 1) { + // sections[0].isActive = true + // return + // } + + // sections.forEach((section, index) => { + // if (index === 0) { + // section.isActive = sections[index + 1].boundingTop > offsetY + marginTop + // } else { + // if (sections[index + 1]) { + // section.isActive = + // sections[index + 1].boundingTop > offsetY + marginTop && + // sections[index].boundingTop <= offsetY + marginTop + // } else { + // section.isActive = sections[index].boundingTop <= offsetY + marginTop + // } + // } + // }) + // }, [sections, offsetY]) + + // useEffect(() => { + // const observer = new IntersectionObserver((entries) => { + // // console.log('entries', entries) + // const entry = entries[0] + // // console.log('entry', entry) + // }) + // // console.log('myRef', myRef.current) + // observer.observe(myRef.current) + // }, []) + + const router = useRouter() + + function updateUrl(key) { + // router.replace( + // { + // pathname: `/ref/js/${key}`, + // // query: { sortBy: 'price' }, + // } + // // undefined, + // // { shallow: true } + // ) + router.replace( + { + pathname: `/ref/js/${key}`, + // query: { sortBy: 'price' }, + }, + undefined, + { scroll: false } + ) + } + + return ( +
+
+
+ {sections.map((x, i) => { + return ( + { + window.scrollTo(0, x.boundingTop - marginTop) + setOffsetY(x.boundingTop - marginTop) + }} + > + {x.topic} + + ) + })} +
+ +
+
+ {jsSpec.functions.map((item, itemIndex) => { + // if (item.id !== 'select()') return
hidden section
+ // const sectionRef = useRef(null) + + // console.log('x', x) + const hasTsRef = item['$ref'] || null + // console.log('hasTsRef', hasTsRef) + // console.log('jsTypeSpec', jsTypeSpec) + const tsDefinition = hasTsRef && extractTsDocNode(hasTsRef, jsTypeSpec) + // console.log('tsDefinition', tsDefinition) + // console.log(`tsDefinition for ${item.title ?? item.id}`, tsDefinition) + + // useEffect(() => { + // const observer = new IntersectionObserver((entries) => { + // // console.log('entries', entries) + // const entry = entries[0] + + // // console.log( + // // x.id, + // // 'intersectiong', + // // entry.isIntersecting, + // // 'visible', + // // entry.isVisible + // // ) + // }) + // // console.log('myRef', myRef.current) + // observer.observe(sectionRef.current) + // }, []) + + const parameters = hasTsRef ? generateParameters(tsDefinition) : '' + + // @ts-ignore + // const [serialFunctionMarkdownContent, setSerialFunctionMarkdownContent] = + // useState(null) + + const functionMarkdownContent = props?.docs[itemIndex]?.content + + // useEffect(() => { + // async function makeContent() { + // setSerialFunctionMarkdownContent( + // await serialize(functionMarkdownContent, { + // mdxOptions: { + // remarkPlugins: [remarkGfm], + // format: 'mdx', + // }, + // }) + // ) + // } + // makeContent() + // }, []) + + // console.log('serialFunctionMarkdownContent', serialFunctionMarkdownContent) + + return ( + <> +
+

updateUrl(item.id)}> + {examples.functions[itemIndex].title ?? + examples.functions[itemIndex].id ?? + item.name ?? + item.id} +

+
+
+
+

+ {examples.functions[itemIndex].description} +

+ +
+ {functionMarkdownContent && ( + + )} + + {item.notes && ( +
+ {item.notes} +
+ )} + + {/* // parameters */} + {parameters &&
} +
+
+
+ {item.examples && ( + + {item.examples && + item.examples.map((example, exampleIndex) => { + const exampleString = ` +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') +` + const currentExampleId = example.id + // const staticExample = + // examples.functions[itemIndex].examples[exampleIndex] + + // const response = staticExample.response + // const sql = staticExample?.data?.sql + // const tables = staticExample?.data?.tables + + return ( + + + {exampleString + + (example.code && + example.code + .replace('```', '') + .replace('js', '') + .replace('```', ''))} + + + ) + })} + + )} +
+
+
+ + ) + })} +
+
+
+
+ ) +} + +export async function getStaticProps({ params }: { params: { slug: string[] } }) { + /** + * This is our collection of human readable titles and IDs + */ + let markdownDocs = [ + { + title: 'Inserting data', + id: 'select()', + }, + { title: 'Deleting data', id: 'delete()' }, + ] + + const pages = jsSpec.functions.map((x) => x.id) + console.log('pages', pages) + + /** + * Read all the markdown files that might have + * - custom text + * - call outs + * - important notes regarding implementation + */ + const allMarkdownDocs = await Promise.all( + pages.map(async (x, i) => { + // const doc = getDocsBySlug(`docs/ref/database/${x}`) + + // if (i >= 5) return null + + const pathName = `docs/ref/js/${x}.mdx` + + function checkFileExists(x) { + // console.log('checking this ', x) + if (fs.existsSync(x)) { + return true + } else { + return false + } + } + + const markdownExists = checkFileExists(pathName) + + console.log(x, 'markdownExists', markdownExists) + + const fileContents = markdownExists ? fs.readFileSync(pathName, 'utf8') : '' + const { data, content } = matter(fileContents) + // console.log('docBySlug', content) + // console.log() + + if (content) console.log(content) + return { + id: x, + title: x, + // ...content, + meta: data, + content: content ? await serialize(content || '') : null, + } + }) + ) + + // console.log('allMarkdownDocs', allMarkdownDocs) + + return { + props: { + docs: allMarkdownDocs, + }, + } +} + +export function getStaticPaths() { + let docs = getAllDocs() + + return { + paths: docs.map(() => { + return { + params: { + slug: docs.map((d) => d.slug), + }, + } + }), + fallback: 'blocking', + } +} diff --git a/apps/docs/pages/new/ref/index.mdx b/apps/docs/pages/new/reference/index.mdx similarity index 100% rename from apps/docs/pages/new/ref/index.mdx rename to apps/docs/pages/new/reference/index.mdx diff --git a/apps/docs/pages/new/ref/js/[...slug].tsx b/apps/docs/pages/new/reference/javascript/[...slug].tsx similarity index 100% rename from apps/docs/pages/new/ref/js/[...slug].tsx rename to apps/docs/pages/new/reference/javascript/[...slug].tsx diff --git a/apps/docs/pages/new/reference/javascript/v1/[...slug].tsx b/apps/docs/pages/new/reference/javascript/v1/[...slug].tsx new file mode 100644 index 00000000000..e07b7a69cfb --- /dev/null +++ b/apps/docs/pages/new/reference/javascript/v1/[...slug].tsx @@ -0,0 +1,442 @@ +import { + useEffect, + // useRef, + useState, +} from 'react' +// pages/index.js + +import fs from 'fs' + +import matter from 'gray-matter' +import { MDXRemote } from 'next-mdx-remote' +import { serialize } from 'next-mdx-remote/serialize' +import remarkGfm from 'remark-gfm' +import components from '~/components/index' +import { getAllDocs } from '~/lib/docs' + +import ReactMarkdown from 'react-markdown' + +// @ts-ignore +import jsTypeSpec from '~/../../spec/enrichments/tsdoc_v1/combined.json' +// @ts-ignore +import examples from '~/../../spec/examples/examples.yml' assert { type: 'yml' } +// @ts-expect-error +import jsSpec from '~/../../spec/supabase_js_v1_temp_new_shape.yml' assert { type: 'yml' } + +import { IconDatabase, Tabs } from 'ui' +import CodeBlock from '~/components/CodeBlock/CodeBlock' + +import { useRouter } from 'next/router' +import { extractTsDocNode, generateParameters } from '~/lib/refGenerator/helpers' + +const marginTop = 256 +export default function Ref(props) { + // const myRef = useRef(null) + + console.log('props', props) + + const [offsetY, setOffsetY] = useState(0) + const [sections, setSections] = useState([]) + + // useEffect(() => { + // window.scrollTo(0, 0) + // setOffsetY(0) + // }, []) + + useEffect(() => { + const els: HTMLElement[] = Array.from(document.querySelectorAll('div.ref-container')) + + const allSections = els.map((el: HTMLElement, index: number) => { + const { top: boundingTop } = el.getBoundingClientRect() + + return { + topic: el.getAttribute('id')!, + boundingTop, + isActive: index === 0, + } + }) + + // console.log('allSections', allSections) + setSections(allSections) + }, []) + + // useEffect(() => { + // if (sections.length <= 1) return + + // const onScroll = () => { + // console.log('SCROLL EVENT') + // setOffsetY(window.pageYOffset) + // } + // window.addEventListener('scroll', debounce(onScroll, 500)) + + // return () => window.removeEventListener('scroll', onScroll) + // }, [sections]) + + // useEffect(() => { + // if (sections.length === 0) return + + // if (sections.length === 1) { + // sections[0].isActive = true + // return + // } + + // sections.forEach((section, index) => { + // if (index === 0) { + // section.isActive = sections[index + 1].boundingTop > offsetY + marginTop + // } else { + // if (sections[index + 1]) { + // section.isActive = + // sections[index + 1].boundingTop > offsetY + marginTop && + // sections[index].boundingTop <= offsetY + marginTop + // } else { + // section.isActive = sections[index].boundingTop <= offsetY + marginTop + // } + // } + // }) + // }, [sections, offsetY]) + + // useEffect(() => { + // const observer = new IntersectionObserver((entries) => { + // // console.log('entries', entries) + // const entry = entries[0] + // // console.log('entry', entry) + // }) + // // console.log('myRef', myRef.current) + // observer.observe(myRef.current) + // }, []) + + const router = useRouter() + + function updateUrl(key) { + // router.replace( + // { + // pathname: `/ref/js/${key}`, + // // query: { sortBy: 'price' }, + // } + // // undefined, + // // { shallow: true } + // ) + router.replace( + { + pathname: `/ref/js/${key}`, + // query: { sortBy: 'price' }, + }, + undefined, + { scroll: false } + ) + } + + return ( +
+
+
+ {sections.map((x, i) => { + return ( + { + window.scrollTo(0, x.boundingTop - marginTop) + setOffsetY(x.boundingTop - marginTop) + }} + > + {x.topic} + + ) + })} +
+ +
+
+ {jsSpec.functions.map((item, itemIndex) => { + // if (item.id !== 'select()') return
hidden section
+ // const sectionRef = useRef(null) + + // console.log('x', x) + const hasTsRef = item['$ref'] || null + // console.log('hasTsRef', hasTsRef) + // console.log('jsTypeSpec', jsTypeSpec) + const tsDefinition = hasTsRef && extractTsDocNode(hasTsRef, jsTypeSpec) + // console.log('tsDefinition', tsDefinition) + // console.log(`tsDefinition for ${item.title ?? item.id}`, tsDefinition) + + // useEffect(() => { + // const observer = new IntersectionObserver((entries) => { + // // console.log('entries', entries) + // const entry = entries[0] + + // // console.log( + // // x.id, + // // 'intersectiong', + // // entry.isIntersecting, + // // 'visible', + // // entry.isVisible + // // ) + // }) + // // console.log('myRef', myRef.current) + // observer.observe(sectionRef.current) + // }, []) + + const parameters = hasTsRef ? generateParameters(tsDefinition) : '' + + // @ts-ignore + // const [serialFunctionMarkdownContent, setSerialFunctionMarkdownContent] = + // useState(null) + + const functionMarkdownContent = props?.docs[itemIndex]?.content + + // useEffect(() => { + // async function makeContent() { + // setSerialFunctionMarkdownContent( + // await serialize(functionMarkdownContent, { + // mdxOptions: { + // remarkPlugins: [remarkGfm], + // format: 'mdx', + // }, + // }) + // ) + // } + // makeContent() + // }, []) + + // console.log('serialFunctionMarkdownContent', serialFunctionMarkdownContent) + + return ( + <> +
+

updateUrl(item.id)}> + {examples.functions[itemIndex].title ?? + examples.functions[itemIndex].id ?? + item.name ?? + item.id} +

+
+
+
+

+ {examples.functions[itemIndex].description} +

+ +
+ {functionMarkdownContent && ( + + )} + + {item.notes && ( +
+ {item.notes} +
+ )} + + {/* // parameters */} + {parameters &&
} +
+
+
+ {item.examples && ( + + {item.examples && + item.examples.map((example, exampleIndex) => { + const exampleString = ` +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') +` + const currentExampleId = example.id + + const staticExample = + examples?.functions[itemIndex]?.examples && + examples?.functions[itemIndex]?.examples[exampleIndex] + + const response = staticExample?.response + const sql = staticExample?.data?.sql + const tables = staticExample?.data?.tables + + return ( + + {tables && + tables.length > 0 && + tables.map((table) => { + console.log(table) + + // @ts-ignore + // const [content, setContent] = useState(null) + + // // @ts-ignore + // useEffect(() => { + // async function makeContent() { + // setContent( + // await serialize(table.content, { + // mdxOptions: { + // remarkPlugins: [remarkGfm], + // format: 'mdx', + // }, + // }) + // ) + // } + // makeContent() + // }, []) + + return ( +
+
+
+
+ +
+
+ {table.name} +
+
+
+ + {/* {table.content} */} + {/* {content && } */} +
+ ) + })} + {sql && ( + + {sql} + + )} + + {exampleString + + (example.code && + example.code + .replace('```', '') + .replace('js', '') + .replace('```', ''))} + + {response && ( + + {response} + + )} +
+ ) + })} +
+ )} +
+
+
+ + ) + })} +
+
+
+
+ ) +} + +export async function getStaticProps({ params }: { params: { slug: string[] } }) { + /** + * This is our collection of human readable titles and IDs + */ + let markdownDocs = [ + { + title: 'Inserting data', + id: 'select()', + }, + { title: 'Deleting data', id: 'delete()' }, + ] + + const pages = jsSpec.functions.map((x) => x.id) + console.log('pages', pages) + + /** + * Read all the markdown files that might have + * - custom text + * - call outs + * - important notes regarding implementation + */ + const allMarkdownDocs = await Promise.all( + pages.map(async (x, i) => { + // const doc = getDocsBySlug(`docs/ref/database/${x}`) + + // if (i >= 5) return null + + const pathName = `docs/ref/js/${x}.mdx` + + function checkFileExists(x) { + // console.log('checking this ', x) + if (fs.existsSync(x)) { + return true + } else { + return false + } + } + + const markdownExists = checkFileExists(pathName) + + console.log(x, 'markdownExists', markdownExists) + + const fileContents = markdownExists ? fs.readFileSync(pathName, 'utf8') : '' + const { data, content } = matter(fileContents) + // console.log('docBySlug', content) + // console.log() + + if (content) console.log(content) + return { + id: x, + title: x, + // ...content, + meta: data, + content: content ? await serialize(content || '') : null, + } + }) + ) + + // console.log('allMarkdownDocs', allMarkdownDocs) + + return { + props: { + docs: allMarkdownDocs, + }, + } +} + +export function getStaticPaths() { + let docs = getAllDocs() + + return { + paths: docs.map(() => { + return { + params: { + slug: docs.map((d) => d.slug), + }, + } + }), + fallback: 'blocking', + } +} diff --git a/apps/docs/public/img/gradient-bg.png b/apps/docs/public/img/gradient-bg.png new file mode 100644 index 00000000000..ff11607e143 Binary files /dev/null and b/apps/docs/public/img/gradient-bg.png differ diff --git a/apps/docs/public/img/icons/menu/edge-functions.svg b/apps/docs/public/img/icons/menu/functions.svg similarity index 100% rename from apps/docs/public/img/icons/menu/edge-functions.svg rename to apps/docs/public/img/icons/menu/functions.svg diff --git a/apps/docs/public/img/icons/menu/getting-started.svg b/apps/docs/public/img/icons/menu/gettingstarted.svg similarity index 100% rename from apps/docs/public/img/icons/menu/getting-started.svg rename to apps/docs/public/img/icons/menu/gettingstarted.svg diff --git a/apps/docs/public/img/icons/menu/api.svg b/apps/docs/public/img/icons/menu/reference.svg similarity index 100% rename from apps/docs/public/img/icons/menu/api.svg rename to apps/docs/public/img/icons/menu/reference.svg diff --git a/spec/supabase_dart_v1_temp_new_shape.yml b/spec/supabase_dart_v1_temp_new_shape.yml new file mode 100644 index 00000000000..04997e1ff5b --- /dev/null +++ b/spec/supabase_dart_v1_temp_new_shape.yml @@ -0,0 +1,2438 @@ +openref: 0.1 + +info: + id: reference/dart + title: Getting started + description: | + + Supabase Dart. + + definition: ../../spec/enrichments/tsdoc_v2/combined.json + slugPrefix: '/' + specUrl: https://github.com/supabase/supabase/edit/master/spec/supabase_dart_v1.yml + libraries: + - name: 'Dart' + id: 'dart' + version: '0.0.1' + +functions: + - id: auth.signUp() + title: 'signUp()' + description: | + Creates a new user. + notes: | + - By default, the user needs to verify their email address before logging in. To turn this off, disable **Confirm email** in [your project](https://app.supabase.com/project/_/auth/settings). + - **Confirm email** determines if users need to confirm their email address after signing up. + - If **Confirm email** is enabled, a `user` is returned but `session` is null. + - If **Confirm email** is disabled, both a `user` and a `session` are returned. + - When the user confirms their email address, they are redirected to the [`SITE_URL`](https://supabase.com/docs/reference/auth/config#site_url) by default. You can modify your `SITE_URL` or add additional redirect URLs in [your project](https://app.supabase.com/project/_/auth/settings). + - If signUp() is called for an existing confirmed user: + - If **Confirm email** is enabled in [your project](https://app.supabase.com/project/_/auth/settings), an obfuscated/fake user object is returned. + - If **Confirm email** is disabled, the error message, `User already registered` is returned. + examples: + - id: sign-up. + name: Sign up. + isSpotlight: true + code: | + ```dart + final AuthResponse res = await supabase.auth.signUp( + email: 'example@email.com', + password: 'example-password', + ); + final Session? session = res.session; + final User? user = res.user; + ``` + - id: sign-up-with-third-party-providers. + name: Sign up with third-party providers. + hideCodeBlock: true + description: | + If you are using Flutter, you can sign up with OAuth providers using the [`signInWithOAuth()`](/docs/reference/dart/auth-signinwithoauth) method available on `supabase_flutter`. + + - id: auth.signInWithPassword() + title: 'signInWithPassword()' + description: | + Log in an existing user using email or phone number with password. + notes: | + - Requires either an email and password or a phone number and password. + examples: + - id: sign-in-with-email-and-password + name: Sign in with email and password + isSpotlight: true + code: | + ```dart + final AuthResponse res = await supabase.auth.signInWithPassword( + email: 'example@email.com', + password: 'example-password', + ); + final Session? session = res.session; + final User? user = res.user; + ``` + - id: sign-in-with-phone-and-password + name: Sign in with phone and password + code: | + ```dart + final AuthResponse res = await supabase.auth.signInWithPassword( + phone: '+13334445555', + password: 'example-password', + ); + final Session? session = res.session; + final User? user = res.user; + ``` + - id: auth.signInWithOtp() + title: 'signInWithOtp()' + notes: | + - Requires either an email or phone number. + - This method is used for passwordless sign-ins where a OTP is sent to the user's email or phone number. + - If you're using an email, you can configure whether you want the user to receive a magiclink or a OTP. + - If you're using phone, you can configure whether you want the user to receive a OTP. + - The magic link's destination URL is determined by the [`SITE_URL`](https://supabase.com/docs/reference/auth/config#site_url). You can modify the `SITE_URL` or add additional redirect urls in [your project](https://app.supabase.com/project/_/auth/settings). + examples: + - id: sign-in-with-email. + name: Sign in with email. + isSpotlight: true + description: | + The user will be sent an email which contains either a magiclink or a OTP or both. By default, a given user can only request a OTP once every 60 seconds. + You can pass `emailRedirectTo` with dynamic link to bring the users back to your app after they click on the magic link. + code: | + ```dart + await supabase.auth.signInWithOtp( + email: 'example@email.com', + emailRedirectTo: kIsWeb ? null : 'io.supabase.flutter://signin-callback/', + ); + ``` + - id: sign-in-with-sms-otp. + name: Sign in with SMS OTP. + description: The user will be sent a SMS which contains a OTP. By default, a given user can only request a OTP once every 60 seconds. + code: | + ```dart + await supabase.auth.signInWithOtp( + phone: '+13334445555', + ); + ``` + - id: auth.signInWithOAuth() + title: 'signInWithOAuth()' + description: | + Signs the user in using third party OAuth providers. + notes: | + - This method is used for signing in using a third-party provider. + - Supabase supports many different [third-party providers](https://supabase.com/docs/guides/auth#providers). + examples: + - id: sign-in-using-a-third-party-provider + name: Sign in using a third-party provider + isSpotlight: true + code: | + ```dart + await supabase.auth.signInWithOAuth(Provider.github); + ``` + - id: with`redirectto` + name: With `redirectTo` + description: | + Specify the redirect link to bring back the user via deeplink. + Note that `redirectTo` should be null for Flutter Web. + code: | + ```dart + await supabase.auth.signInWithOAuth( + Provider.github, + redirectTo: kIsWeb ? null : 'io.supabase.flutter://reset-callback/', + ); + ``` + - id: with-scopes + name: 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. + code: | + ```dart + await supabase.auth.signInWithOAuth( + Provider.github, + scopes: 'repo gist notifications' + ); + ... + // after user comes back from signin flow + + final Session? session = supabase.auth.currentSession; + final String? oAuthToken = session?.providerToken; + ``` + - id: auth.signOut() + title: 'signOut()' + description: | + Signs out the current user, if there is a logged in user. + notes: | + - In order to use the `signOut()` method, the user needs to be signed in first. + examples: + - id: sign-out + name: Sign out + isSpotlight: true + code: | + ```dart + await supabase.auth.signOut(); + ``` + - id: auth.verifyOtp() + title: 'verifyOtp()' + notes: | + - The `verifyOtp` method takes in different verification types. If a phone number is used, the type can either be `sms` or `phone_change`. If an email address is used, the type can be one of the following: `signup`, `magiclink`, `recovery`, `invite` or `email_change`. + - The verification type used should be determined based on the corresponding auth method called before `verifyOtp` to sign up / sign-in a user. + examples: + - id: verify-sms-one-time-password(otp) + name: Verify Sms One-Time Password (OTP) + isSpotlight: true + code: | + ```dart + final AuthResponse res = await supabase.auth.verifyOTP( + type: OtpType.sms, + token: '111111', + phone: '+13334445555', + ); + final Session? session = res.session; + final User? user = res.user; + ``` + - id: verify-signup-one-time-password(otp) + name: Verify Signup One-Time Password (OTP) + isSpotlight: false + code: | + ```dart + final AuthResponse res = await supabase.auth.verifyOTP( + type: OtpType.signup, + token: token, + phone: '+13334445555', + ); + final Session? session = res.session; + final User? user = res.user; + ``` + - id: auth.currentSession + title: 'currentSession' + description: | + Returns the session data, if there is an active session. + examples: + - id: get-the-session-data + name: Get the session data + isSpotlight: true + code: | + ```dart + final Session? session = supabase.auth.currentSession; + ``` + - id: auth.currentUser + title: 'currentUser' + description: | + Returns the user data, if there is a logged in user. + examples: + - id: get-the-logged-in-user + name: Get the logged in user + isSpotlight: true + code: | + ```dart + final User? user = supabase.auth.currentUser; + ``` + - id: auth.updateUser() + title: 'updateUser()' + description: | + Updates user data, if there is a logged in user. + notes: | + - In order to use the `updateUser()` method, the user needs to be signed in first. + - By Default, email updates sends a confirmation link to both the user's current and new email. + To only send a confirmation link to the user's new email, disable **Secure email change** in your project's [email auth provider settings](https://app.supabase.com/project/_/auth/settings). + examples: + - id: update-the-email-for-an-authenticated-user + name: Update the email for an authenticated user + description: Sends a "Confirm Email Change" email to the new email address. + isSpotlight: true + code: | + ```dart + final UserResponse res = await supabase.auth.updateUser( + UserAttributes( + email: 'example@email.com', + ), + ); + final User? updatedUser = res.user; + ``` + - id: update-the-password-for-an-authenticated-user + name: Update the password for an authenticated user + isSpotlight: false + code: | + ```dart + final UserResponse res = await supabase.auth.updateUser( + UserAttributes( + password: 'new password', + ), + ); + final User? updatedUser = res.user; + ``` + - id: update-the-user's-metadata + name: Update the user's metadata + isSpotlight: true + code: | + ```dart + final UserResponse res = await supabase.auth.updateUser( + UserAttributes( + data: { 'hello': 'world' }, + ), + ); + final User? updatedUser = res.user; + ``` + - id: auth.onAuthStateChange() + title: 'onAuthStateChange()' + description: | + Receive a notification every time an auth event happens. + notes: | + - Types of auth events: `AuthChangeEvent.passwordRecovery`, `AuthChangeEvent.signedIn`, `AuthChangeEvent.signedOut`, `AuthChangeEvent.tokenRefreshed`, `AuthChangeEvent.userUpdated`and `AuthChangeEvent.userDeleted` + examples: + - id: listen-to-auth-changes + name: Listen to auth changes + isSpotlight: true + code: | + ```dart + final authSubscription = supabase.auth.onAuthStateChange.listen((data) { + final AuthChangeEvent event = data.event; + final Session? session = data.session; + }); + ``` + - id: listen-to-a-specific-event + name: Listen to a specific event + code: | + ```dart + final authSubscription = supabase.auth.onAuthStateChange.listen((data) { + final AuthChangeEvent event = data.event; + if (event == AuthChangeEvent.signedIn) { + // handle signIn + } + }); + ``` + - id: unsubscribe-from-auth-subscription + name: Unsubscribe from auth subscription + code: | + ```dart + final authSubscription = supabase.auth.onAuthStateChange((event, session) {}); + + authSubscription.cancel(); + ``` + - id: auth.resetPasswordForEmail + title: 'resetPasswordForEmail()' + description: | + Sends a reset request to an email address. + notes: | + Sends a password reset request to an email address. When the user clicks the reset link in the email they are redirected back to your application. Prompt the user for a new password and call auth.updateUser(): + + ```dart + await supabase.auth.resetPasswordForEmail( + 'sample@email.com', + redirectTo: kIsWeb ? null : 'io.supabase.flutter://reset-callback/', + ); + ``` + examples: + - id: reset-password-for-flutter + name: Reset password for Flutter + isSpotlight: true + code: | + `redirectTo` is used to open the app via deeplink when user opens the password reset email. + ```dart + await supabase.auth.resetPasswordForEmail( + 'sample@email.com', + redirectTo: kIsWeb ? null : 'io.supabase.flutter://reset-callback/', + ); + ``` + - id: invoke() + title: 'invoke()' + description: | + Invokes a Supabase Function. See the [guide](/docs/guides/functions) for details on writing Functions. + notes: | + - Requires an Authorization header. + - Invoke params generally match the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) spec. + examples: + - id: basic-invocation. + name: Basic invocation. + isSpotlight: true + code: | + ```dart + final res = await supabase.functions.invoke('hello', body: {'foo': 'baa'}); + final data = res.data; + ``` + - id: specifying-response-type. + name: Specifying response type. + description: | + By default, `invoke()` will parse the response as JSON. You can parse the response in the following formats: `json`, `blob`, `text`, and `arrayBuffer`. + isSpotlight: true + code: | + ```dart + final res = await supabase.functions.invoke( + 'hello', + body: {'foo': 'baa'}, + responseType: ResponseType.text, + ); + final data = res.data; + ``` + - id: parsing-custom-headers. + name: Parsing custom headers. + description: | + Any `headers` will be passed through to the function. A common pattern is to pass a logged-in user's JWT token as an Authorization header. + isSpotlight: true + code: | + ```dart + final res = await supabase.functions.invoke( + 'hello', + body: {'foo': 'baa'}, + headers: { + 'Authorization': 'Bearer ${supabase.auth.currentSession?.accessToken}' + }, + ); + ``` + - id: select() + description: | + Performs vertical filtering with SELECT. + title: 'Fetch data: select()' + notes: | + - By default, Supabase projects will return a maximum of 1,000 rows. This setting can be changed in 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/dart/using-modifiers) + - `select()` can be combined with [Filters](/docs/reference/dart/using-filters) + - If using the Supabase hosted platform `apikey` is technically a reserved keyword, since the API gateway will pluck it out for authentication. [It should be avoided as a column name](https://github.com/supabase/supabase/issues/5465). + examples: + - id: getting-your-data + name: Getting your data + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('cities') + .select('name'); + ``` + - id: selecting-specific-columns + name: Selecting specific columns + description: You can select specific fields from your tables. + code: | + ```dart + final data = await supabase + .from('countries') + .select(''' + name, + cities ( + name + ) + '''); + ``` + - id: query-foreign-tables + name: Query foreign tables + description: If your database has relationships, you can query related tables too. + code: | + ```dart + final data = await supabase + .from('products') + .select(''' + id, + supplier:supplier_id ( name ), + purchaser:purchaser_id ( name ) + '''); + ``` + - id: query-the-same-foreign-table-multiple-times + 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: + code: | + ```dart + final data = await supabase + .from('messages') + .select('*, users!inner(*)') + .eq('users.username', 'Jane'); + ``` + - id: filtering-with-inner-joins + name: Filtering with inner joins + description: | + If you want to filter a table based on a child table's values you can use the `!inner()` function. For example, if you wanted + to select all rows in a `message` table which belong to a user with the `username` "Jane": + code: | + ```dart + final data = await supabase + .from('messages') + .select('*, users!inner(*)') + .eq('users.username', 'Jane'); + ``` + - id: querying-with-count-option + name: Querying with count option + description: | + You can get the number of rows by using the count option. + Allowed values for count option are [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). + code: | + ```dart + final res = await supabase.from('cities').select( + 'name', + const FetchOptions( + count: CountOption.exact, + ), + ); + + final count = res.count; + ``` + - id: querying-json-data + 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. + code: | + ```dart + final data = await supabase + .from('users') + .select(''' + id, name, + address->street + ''') + .eq('address->postcode', 90210); + ``` + - id: return-data-as-csv + 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. + code: | + ```dart + final data = await supabase + .from('users') + .select() + .csv(); + ``` + + - id: insert() + description: | + Performs an INSERT into the table. + title: 'Create data: insert()' + examples: + - id: create-a-record + name: Create a record + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('cities') + .insert({'name': 'The Shire', 'country_id': 554}); + ``` + - id: bulk-create + name: Bulk create + code: | + ```dart + final res = await supabase.from('cities').insert([ + {'name': 'The Shire', 'country_id': 554}, + {'name': 'Rohan', 'country_id': 555}, + ]); + ``` + + - id: update() + description: | + Performs an UPDATE on the table. + title: 'Modify data: update()' + notes: | + - `update()` should always be combined with [Filters](/docs/reference/dart/using-filters) to target the item(s) you wish to update. + examples: + - id: updating-your-data + name: Updating your data + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('cities') + .update({ 'name': 'Middle Earth' }) + .match({ 'name': 'Auckland' }); + ``` + - id: updating-json-data + 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. + code: | + ```dart + final data = await supabase + .from('users') + .update({ + 'address': { + 'street': 'Melrose Place', + 'postcode': 90210 + } + }) + .eq('address->postcode', 90210); + ``` + + - id: upsert() + description: | + Performs an UPSERT into the table. + title: 'Upsert data: upsert()' + notes: | + - Primary keys should 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: + - id: upsert-your-data + name: Upsert your data + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('messages') + .upsert({ 'id': 3, 'message': 'foo', 'username': 'supabot' }); + ``` + - id: upserting-into-tables-with-constraints + 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 + code: | + ```dart + final data = await supabase + .from('users') + .upsert({ 'username': 'supabot' }, { 'onConflict': 'username' }); + ``` + - id: return-the-exact-number-of-rows + name: Return the exact number of rows + description: | + Allowed values for count option are `exact`, `planned` and `estimated`. + code: | + ```dart + final res = await supabase.from('users').upsert( + {'id': 3, 'message': 'foo', 'username': 'supabot'}, + options: const FetchOptions(count: CountOption.exact), + ); + + final data = res.data; + final count = res.count; + ``` + + - id: delete() + description: | + Performs a DELETE on the table. + title: 'Delete data: delete()' + notes: | + - `delete()` should always be combined with [Filters](/docs/reference/dart/using-filters) to target the item(s) you wish to delete. + examples: + - id: delete-records + name: Delete records + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('cities') + .delete() + .match({ 'id': 666 }); + ``` + + - id: rpc() + title: 'Stored Procedures: rpc()' + description: | + You can call stored procedures 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. + examples: + - id: call-a-stored-procedure + name: Call a stored procedure + isSpotlight: true + description: This is an example invoking a stored procedure. + code: | + ```dart + final data = await supabase + .rpc('hello_world'); + ``` + - id: with-parameters + name: With Parameters + code: | + ```dart + final data = await supabase + .rpc('echo_city', params: { 'name': 'The Shire' }); + ``` + + - id: subscribe() + description: | + Subscribe to realtime changes in your database. + title: 'on().subscribe()' + 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: + - id: listen-to-all-database-changes + name: Listen to all database changes + isSpotlight: true + code: | + ```dart + supabase.channel('*').on( + RealtimeListenTypes.postgresChanges, + ChannelFilter(event: '*', schema: '*'), + (payload, [ref]) { + print('Change received: ${payload.toString()}'); + }, + ).subscribe(); + ``` + - id: listening-to-a-specific-table + name: Listening to a specific table + code: | + ```dart + supabase.channel('public:countries').on( + RealtimeListenTypes.postgresChanges, + ChannelFilter(event: '*', schema: 'public', table: 'countries'), + (payload, [ref]) { + print('Change received: ${payload.toString()}'); + }, + ).subscribe(); + ``` + - id: listening-to-inserts + name: Listening to inserts + code: | + ```dart + supabase.channel('public:countries').on( + RealtimeListenTypes.postgresChanges, + ChannelFilter(event: 'INSERT', schema: 'public', table: 'countries'), + (payload, [ref]) { + print('Change received: ${payload.toString()}'); + }, + ).subscribe(); + ``` + - id: listening-to-updates + 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; + ``` + code: | + ```dart + supabase.channel('public:countries').on( + RealtimeListenTypes.postgresChanges, + ChannelFilter(event: 'UPDATE', schema: 'public', table: 'countries'), + (payload, [ref]) { + print('Change received: ${payload.toString()}'); + }, + ).subscribe(); + ``` + - id: listening-to-deletes + 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; + ``` + code: | + ```dart + supabase.channel('public:countries').on( + RealtimeListenTypes.postgresChanges, + ChannelFilter(event: 'DELETE', schema: 'public', table: 'countries'), + (payload, [ref]) { + print('Change received: ${payload.toString()}'); + }, + ).subscribe(); + ``` + - id: listening-to-multiple-events + name: Listening to multiple events + description: You can chain listeners if you want to listen to multiple events for each table. + code: | + ```dart + supabase.channel('public:countries').on(RealtimeListenTypes.postgresChanges, + ChannelFilter(event: 'INSERT', schema: 'public', table: 'countries'), + (payload, [ref]) { + print('Change received: ${payload.toString()}'); + }).on(RealtimeListenTypes.postgresChanges, + ChannelFilter(event: 'DELETE', schema: 'public', table: 'countries'), + (payload, [ref]) { + print('Change received: ${payload.toString()}'); + }).subscribe(); + ``` + - id: listening-to-row-level-changes + 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. + code: | + ```dart + supabase.channel('public:countries:id=eq.200').on( + RealtimeListenTypes.postgresChanges, + ChannelFilter( + event: 'UPDATE', + schema: 'public', + table: 'countries', + filter: 'id=eq.200', + ), (payload, [ref]) { + print('Change received: ${payload.toString()}'); + }).subscribe(); + ``` + + - id: removeChannel() + description: | + Unsubscribes and removes Realtime channel from Realtime client. + title: 'removeChannel()' + notes: | + - Removing a channel is a great way to maintain the performance of your project's Realtime service as well as your database if you're listening to Postgres changes. Supabase will automatically handle cleanup 30 seconds after a client is disconnected, but unused channels may cause degradation as more clients are simultaneously subscribed. + examples: + - id: remove-a-channel + name: Remove a channel + isSpotlight: true + code: | + ```dart + final status = await supabase.removeChannel(channel); + ``` + + - id: removeAllChannels() + description: | + Unsubscribes and removes all Realtime channels from Realtime client. + title: 'removeAllChannels()' + notes: | + - Removing channels is a great way to maintain the performance of your project's Realtime service as well as your database if you're listening to Postgres changes. Supabase will automatically handle cleanup 30 seconds after a client is disconnected, but unused channels may cause degradation as more clients are simultaneously subscribed. + examples: + - id: remove-all-channels + name: Remove all channels + isSpotlight: true + code: | + ```dart + final statuses = await supabase.removeAllChannels(); + ``` + + - id: getChannels() + description: | + Returns all Realtime channels. + title: 'getChannels()' + examples: + - id: get-all-channels + name: Get all channels + isSpotlight: true + code: | + ```dart + final channels = supabase.getChannels(); + ``` + + - id: stream() + description: | + Notifies of data at the queried table. + title: 'stream()' + notes: | + - `stream()` will emit the initial data as well as any further change on the database as `Stream` of `List>` by combining Postgrest and Realtime. + - Takes a list of primary key columns as its argument. + examples: + - id: listening-to-a-specific-table + name: Listening to a specific table + isSpotlight: true + code: | + ```dart + supabase.from('countries') + .stream(primaryKey: ['id']) + .listen((List> data) { + // Do something awesome with the data + }); + ``` + - id: listening-to-a-specific-rows-within-a-table + name: Listening to a specific rows within a table + 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. + This syntax is the as how you can filter data in Realtime + code: | + ```dart + supabase.from('countries') + .stream(primaryKey: ['id']) + .eq('id', '120') + .listen((List> data) { + // Do something awesome with the data + }); + ``` + - id: with`order()` + name: With `order()` + code: | + ```dart + supabase.from('countries') + .stream(primaryKey: ['id']) + .order('name', ascending: true) + .listen((List> data) { + // Do something awesome with the data + }); + ``` + - id: with`limit()` + name: With `limit()` + code: | + ```dart + supabase.from('countries') + .stream(primaryKey: ['id']) + .order('name', ascending: true) + .limit(10) + .listen((List> data) { + // Do something awesome with the data + }); + ``` + - id: using`stream()`with`streambuilder` + name: Using `stream()` with `StreamBuilder` + description: | + When using `stream()` with a `StreamBuilder` within your Flutter application, make sure to store your stream in a variable to prevent refetching upon rebuilding. + code: | + ```dart + final supabase = Supabase.instance.client; + + class MyWidget extends StatefulWidget { + const MyWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyWidgetState(); + } + + class _MyWidgetState extends State { + // Persist the stream in a local variable to prevent refetching upon rebuilds + final _stream = supabase.from('countries').stream(primaryKey: ['id']); + + @override + Widget build(BuildContext context) { + return StreamBuilder( + stream: _stream, + builder: (context, snapshot) { + // Return your widget with the data from the snapshot + }, + ); + } + } + ``` + + - id: storage.listBuckets() + description: | + Retrieves the details of all Storage buckets within an existing product. + title: 'listBuckets()' + $ref: '@supabase/storage-js.packages/StorageBucketApi.default.listBuckets' + notes: | + - Policy permissions required: + - `buckets` permissions: `select` + - `objects` permissions: none + examples: + - id: list-buckets + name: List buckets + isSpotlight: true + code: | + ```dart + final List buckets = await supabase + .storage + .listBuckets(); + ``` + + - id: storage.getBucket() + description: | + Retrieves the details of an existing Storage bucket. + title: 'getBucket()' + $ref: '@supabase/storage-js.packages/StorageBucketApi.default.getBucket' + notes: | + - Policy permissions required: + - `buckets` permissions: `select` + - `objects` permissions: none + examples: + - id: get-bucket + name: Get bucket + isSpotlight: true + code: | + ```dart + final Bucket bucket = await supabase + .storage + .getBucket('avatars'); + ``` + + - id: storage.createBucket() + description: | + Creates a new Storage bucket + title: 'createBucket()' + notes: | + - Policy permissions required: + - `buckets` permissions: `insert` + - `objects` permissions: none + examples: + - id: create-bucket + name: Create bucket + isSpotlight: true + code: | + ```dart + final String bucketId = await supabase + .storage + .createBucket('avatars'); + ``` + + - id: storage.emptyBucket() + description: | + Removes all objects inside a single bucket. + title: 'emptyBucket()' + notes: | + - Policy permissions required: + - `buckets` permissions: `select` + - `objects` permissions: `select` and `delete` + examples: + - id: empty-bucket + name: Empty bucket + isSpotlight: true + code: | + ```dart + final String result = await supabase + .storage + .emptyBucket('avatars'); + ``` + - id: storage.updateBucket() + description: | + Updates a new Storage bucket + title: 'updateBucket()' + notes: | + - Policy permissions required: + - `buckets` permissions: `update` + - `objects` permissions: none + examples: + - id: update-bucket + name: Update bucket + isSpotlight: true + code: | + ```dart + final res = await supabase + .storage + .updateBucket('avatars', const BucketOptions(public: false)); + ``` + + - id: storage.deleteBucket() + description: | + Deletes an existing bucket. A bucket can't be deleted with existing objects inside it. You must first `empty()` the bucket. + title: 'deleteBucket()' + notes: | + - Policy permissions required: + - `buckets` permissions: `select` and `delete` + - `objects` permissions: none + examples: + - id: delete-bucket + name: Delete bucket + isSpotlight: true + code: | + ```dart + final String result = await supabase + .storage + .deleteBucket('avatars'); + ``` + + - id: storage.from.upload() + description: | + Uploads a file to an existing bucket. + title: 'from.upload()' + $ref: '@supabase/storage-js.packages/StorageFileApi.default.upload' + notes: | + - Policy permissions required: + - `buckets` permissions: none + - `objects` permissions: `insert` + examples: + - id: upload-file + name: Upload file + isSpotlight: true + code: | + ```dart + final avatarFile = File('path/to/file'); + final String path = await supabase.storage.from('avatars').upload( + 'public/avatar1.png', + avatarFile, + fileOptions: const FileOptions(cacheControl: '3600', upsert: false), + ); + ``` + + - id: storage.from.update() + description: | + Replaces an existing file at the specified path with a new one. + title: 'from.update()' + notes: | + - Policy permissions required: + - `buckets` permissions: none + - `objects` permissions: `update` and `select` + examples: + - id: update-file + name: Update file + isSpotlight: true + code: | + ```dart + final avatarFile = File('path/to/local/file'); + final String path = await supabase.storage.from('avatars').update( + 'public/avatar1.png', + avatarFile, + fileOptions: const FileOptions(cacheControl: '3600', upsert: false), + ); + ``` + + - id: storage.from.move() + description: | + Moves an existing file, optionally renaming it at the same time. + title: 'from.move()' + notes: | + - Policy permissions required: + - `buckets` permissions: none + - `objects` permissions: `update` and `select` + examples: + - id: move-file + name: Move file + isSpotlight: true + code: | + ```dart + final String result = await supabase + .storage + .from('avatars') + .move('public/avatar1.png', 'private/avatar2.png'); + ``` + + - id: storage.from.createSignedUrl() + description: | + Create signed url to download file without requiring permissions. This URL can be valid for a set number of seconds. + title: 'from.createSignedUrl()' + notes: | + - Policy permissions required: + - `buckets` permissions: none + - `objects` permissions: `select` + examples: + - id: create-signed-url + name: Create Signed URL + isSpotlight: true + code: | + ```dart + final String signedUrl = await supabase + .storage + .from('avatars') + .createSignedUrl('avatar1.png', 60); + ``` + + - id: storage.from.getPublicUrl() + description: | + Retrieve URLs for assets in public buckets + title: 'from.getPublicUrl()' + notes: | + - The bucket needs to be set to public, either via [updateBucket()](/docs/reference/javascript/storage-updatebucket) or by going to Storage on [app.supabase.com](https://app.supabase.com), clicking the overflow menu on a bucket and choosing "Make public" + - Policy permissions required: + - `buckets` permissions: none + - `objects` permissions: none + examples: + - id: returns-the-url-for-an-asset-in-a-public-bucket + name: Returns the URL for an asset in a public bucket + isSpotlight: true + code: | + ```dart + final String publicUrl = supabase + .storage + .from('public-bucket') + .getPublicUrl('avatar1.png'); + ``` + + - id: storage.from.download() + description: | + Downloads a file. + title: 'from.download()' + notes: | + - Policy permissions required: + - `buckets` permissions: none + - `objects` permissions: `select` + examples: + - id: download-file + name: Download file + isSpotlight: true + code: | + ```dart + final Uint8List file = await supabase + .storage + .from('avatars') + .download('avatar1.png'); + ``` + + - id: storage.from.remove() + description: | + Deletes files within the same bucket + title: 'from.remove()' + notes: | + - Policy permissions required: + - `buckets` permissions: none + - `objects` permissions: `delete` and `select` + examples: + - id: delete-file + name: Delete file + isSpotlight: true + code: | + ```dart + final List objects = await supabase + .storage + .from('avatars') + .remove(['avatar1.png']); + ``` + + - id: storage.from.list() + description: | + Lists all the files within a bucket. + title: 'from.list()' + notes: | + - Policy permissions required: + - `buckets` permissions: none + - `objects` permissions: `select` + examples: + - id: list-files-in-a-bucket + name: List files in a bucket + isSpotlight: true + code: | + ```dart + final List objects = await supabase + .storage + .from('avatars') + .list(); + ``` + - id: Using Modifiers + title: Using Modifiers + description: | + Filters work on the row level—they allow you to return rows that + only match certain conditions without changing the shape of the rows. + Modifiers are everything that don't fit that definition—allowing you to + change the format of the response (e.g., returning a CSV string). + + Modifiers must be specified after filters. Some modifiers only apply for + queries that return rows (e.g., `select()` or `rpc()` on a function that + returns a table response). + + - id: limit() + description: | + Limits the result with the specified count. + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('cities') + .select('name, country_id') + .limit(1); + ``` + - id: with-embedded-resources + name: With embedded resources + code: | + ```dart + final data = await supabase + .from('countries') + .select('name, cities(name)') + .eq('name', 'United States') + .limit(1, foreignTable: 'cities' ); + ``` + + - id: order() + description: | + Orders the result with the specified column. + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('cities') + .select('name, country_id') + .order('id', ascending: false ); + ``` + - id: with-embedded-resources + name: With embedded resources + code: | + ```dart + final data = await supabase + .from('countries') + .select('name, cities(name)') + .eq('name', 'United States') + .order('name', foreignTable: 'cities'); + ``` + + - id: range() + description: | + Limits the result to rows within the specified range, inclusive. + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('cities') + .select('name, country_id') + .range(0,3); + ``` + + - id: single() + description: | + Retrieves only one row from the result. Result must be one row (e.g. using limit), otherwise this will result in an error. + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('cities') + .select('name, country_id') + .single(); + ``` + + - id: Using Filters + title: Using Filters + description: | + Filters allow you to only return rows that match certain conditions. + + Filters can be used on `select()`, `update()`, and `delete()` queries. + + If a Database function returns a table response, you can also apply filters. + + ### Applying Filters + + Filters must be applied after any of `select()`, `update()`, `upsert()`, + `delete()`, and `rpc()` and before + [modifiers](/docs/reference/dart/using-modifiers). + + ```dart + final data = await supabase + .from('cities') + .select('name, country_id') + .eq('name', 'The Shire'); // Correct + + final data = 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, + to query cities with population between 1,000 and 10,000: + + ```dart + final data = await supabase + .from('cities') + .select('name, country_id') + .gte('population', 1000) + .lt('population', 10000); + ``` + + ### Conditional Chaining + + Filters can be built up one step at a time and then executed. For example: + + ```dart + final filterByName = null; + final filterPopLow = 1000; + final filterPopHigh = 10000; + + var query = supabase + .from('cities') + .select('name, country_id'); + + if (filterByName != null) { query = query.eq('name', filterByName); } + if (filterPopLow != null) { query = query.gte('population', filterPopLow); } + if (filterPopHigh != null) { query = query.lt('population', filterPopHigh); } + + final data = await query; + ``` + + ### Filter by values within a JSON column + + + + + ```sql + create table + users ( + id int8 primary key, + name text, + address jsonb + ); + + insert into + users (id, name, address) + values + (1, 'Michael', '{ "postcode": 90210 }'), + (2, 'Jane', null); + ``` + + + + + ```dart + final data = await supabase + .from('users') + .select() + .eq('address->postcode', 90210); + ``` + + + + + ```json + { + "data": [ + { + "id": 1, + "name": "Michael", + "address": { + "postcode": 90210 + } + } + ], + "status": 200, + "statusText": "OK" + } + ``` + + + + + ### Filter Foreign Tables + + You can filter on foreign tables in your `select()` query using dot + notation: + + + + + ```sql + create table + countries (id int8 primary key, name text); + create table + cities ( + id int8 primary key, + country_id int8 not null references countries, + name text + ); + + insert into + countries (id, name) + values + (1, 'Germany'), + (2, 'Indonesia'); + insert into + cities (id, country_id, name) + values + (1, 2, 'Bali'), + (2, 1, 'Munich'); + ``` + + + + + ```dart + final data = await supabase + .from('countries') + .select(''' + name, + cities!inner ( + name + ) + ''') + .eq('cities.name', 'Bali'); + ``` + + + + + ```json + { + "data": [ + { + "name": "Indonesia", + "cities": [ + { + "name": "Bali" + } + ] + } + ], + "status": 200, + "statusText": "OK" + } + ``` + + + + + - id: .or() + description: | + Finds all rows satisfying at least one of the filters. + notes: | + - `.or()` expects you to use the raw [PostgREST syntax](https://postgrest.org/en/stable/api.html#horizontal-filtering-rows) for the filter names and values. + + ```dart + .or('id.in.(6,7),arraycol.cs.{"a","b"}') // Use Postgres list () and 'in' for in_ filter. Array {} and 'cs' for contains. + .or('id.in.(${mylist.join(',')}),arraycol.cs.{${mylistArray.join(',')}}') // You can insert a Dart list for list or array column. + .or('id.in.(${mylist.join(',')}),rangecol.cs.(${mylistRange.join(',')}]') // You can insert a Dart list for list or range column. + ``` + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('cities') + .select('name, country_id') + .or('id.eq.20,id.eq.30'); + ``` + - id: use`or`with`and` + name: Use `or` with `and` + code: | + ```dart + final data = await supabase + .from('cities') + .select('name, country_id') + .or('id.gt.20,and(name.eq.New Zealand,name.eq.France)'); + ``` + + - id: .not() + description: | + Finds all rows which doesn't satisfy the filter. + notes: | + - `.not()` expects you to use the raw [PostgREST syntax](https://postgrest.org/en/stable/api.html#horizontal-filtering-rows) for the filter names and values. + + ```dart + .not('name','eq','Paris') + .not('arraycol','cs','{"a","b"}') // Use Postgres array {} for array column and 'cs' for contains. + .not('rangecol','cs','(1,2]') // Use Postgres range syntax for range column. + .not('id','in','(6,7)') // Use Postgres list () and 'in' for in_ filter. + .not('id','in','(${mylist.join(',')})') // You can insert a Dart list array. + ``` + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('cities') + .select('name, country_id') + .not('name', 'eq', 'Paris'); + ``` + - id: with`update()` + name: With `update()` + code: | + ```dart + final data = await supabase + .from('cities') + .update({ 'name': 'Mordor' }) + .not('name', 'eq', 'Paris'); + ``` + - id: with`delete()` + name: With `delete()` + code: | + ```dart + final data = await supabase + .from('cities') + .delete() + .not('name', 'eq', 'Paris'); + ``` + - id: with`rpc()` + name: With `rpc()` + code: | + ```dart + // Only valid if the Stored Procedure returns a table type. + final data = await supabase + .rpc('echo_all_cities) + .not('name', 'eq', 'Paris'); + ``` + + - id: .match() + description: | + Finds all rows whose columns match the specified `query` object. + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('cities') + .select('name, country_id') + .match({'name': 'Beijing', 'country_id': 156}); + ``` + - id: with`update()` + name: With `update()` + code: | + ```dart + final data = await supabase + .from('cities') + .update({ 'name': 'Mordor' }) + .match({'name': 'Beijing', 'country_id': 156}); + ``` + - id: with`delete()` + name: With `delete()` + code: | + ```dart + final data = await supabase + .from('cities') + .delete() + .match({'name': 'Beijing', 'country_id': 156}); + ``` + - id: with`rpc()` + name: With `rpc()` + code: | + ```dart + // Only valid if the Stored Procedure returns a table type. + final data = await supabase + .rpc('echo_all_cities') + .match({'name': 'Beijing', 'country_id': 156}); + ``` + + - id: .eq() + description: | + Finds all rows whose value on the stated `column` exactly matches the specified `value`. + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('cities') + .select('name, country_id') + .eq('name', 'The shire'); + ``` + - id: with`update()` + name: With `update()` + code: | + ```dart + final data = await supabase + .from('cities') + .update({ 'name': 'Mordor' }) + .eq('name', 'San Francisco'); + ``` + - id: with`delete()` + name: With `delete()` + code: | + ```dart + final data = await supabase + .from('cities') + .delete() + .eq('name', 'Mordor'); + ``` + - id: with`rpc()` + name: With `rpc()` + code: | + ```dart + // Only valid if the Stored Procedure returns a table type. + final data = await supabase + .rpc('echo_all_cities') + .eq('name', 'San Francisco'); + ``` + + - id: .neq() + description: | + Finds all rows whose value on the stated `column` doesn't match the specified `value`. + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('cities') + .select('name, country_id') + .neq('name', 'The shire'); + ``` + - id: with`update()` + name: With `update()` + code: | + ```dart + final data = await supabase + .from('cities') + .update({ 'name': 'Mordor' }) + .neq('name', 'San Francisco'); + ``` + - id: with`delete()` + name: With `delete()` + code: | + ```dart + final data = await supabase + .from('cities') + .delete() + .neq('name', 'Mordor'); + ``` + - id: with`rpc()` + name: With `rpc()` + code: | + ```dart + // Only valid if the Stored Procedure returns a table type. + final data = await supabase + .rpc('echo_all_cities') + .neq('name', 'Lagos'); + ``` + + - id: .gt() + description: | + Finds all rows whose value on the stated `column` is greater than the specified `value`. + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('cities') + .select('name, country_id') + .gt('country_id', 250); + ``` + - id: with`update()` + name: With `update()` + code: | + ```dart + final data = await supabase + .from('cities') + .update({ 'name': 'Mordor' }) + .gt('country_id', 250); + ``` + - id: with`delete()` + name: With `delete()` + code: | + ```dart + final data = await supabase + .from('cities') + .delete() + .gt('country_id', 250); + ``` + - id: with`rpc()` + name: With `rpc()` + code: | + ```dart + // Only valid if the Stored Procedure returns a table type. + final data = await supabase + .rpc('echo_all_cities') + .gt('country_id', 250); + ``` + + - id: .gte() + description: | + Finds all rows whose value on the stated `column` is greater than or equal to the specified `value`. + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('cities') + .select('name, country_id') + .gte('country_id', 250); + ``` + - id: with`update()` + name: With `update()` + code: | + ```dart + final data = await supabase + .from('cities') + .update({ 'name': 'Mordor' }) + .gte('country_id', 250); + ``` + - id: with`delete()` + name: With `delete()` + code: | + ```dart + final data = await supabase + .from('cities') + .delete() + .gte('country_id', 250); + ``` + - id: with`rpc()` + name: With `rpc()` + code: | + ```dart + // Only valid if the Stored Procedure returns a table type. + final data = await supabase + .rpc('echo_all_cities') + .gte('country_id', 250); + ``` + + - id: .lt() + description: | + Finds all rows whose value on the stated `column` is less than the specified `value`. + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('cities') + .select('name, country_id') + .lt('country_id', 250); + ``` + - id: with`update()` + name: With `update()` + code: | + ```dart + final data = await supabase + .from('cities') + .update({ 'name': 'Mordor' }) + .lt('country_id', 250); + ``` + - id: with`delete()` + name: With `delete()` + code: | + ```dart + final data = await supabase + .from('cities') + .delete() + .lt('country_id', 250); + ``` + - id: with`rpc()` + name: With `rpc()` + code: | + ```dart + // Only valid if the Stored Procedure returns a table type. + final data = await supabase + .rpc('echo_all_cities') + .lt('country_id', 250); + ``` + + - id: .lte() + description: | + Finds all rows whose value on the stated `column` is less than or equal to the specified `value`. + $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.lte' + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('cities') + .select('name, country_id') + .lte('country_id', 250); + ``` + - id: with`update()` + name: With `update()` + code: | + ```dart + final data = await supabase + .from('cities') + .update({ 'name': 'Mordor' }) + .lte('country_id', 250); + ``` + - id: with`delete()` + name: With `delete()` + code: | + ```dart + final data = await supabase + .from('cities') + .delete() + .lte('country_id', 250); + ``` + - id: with`rpc()` + name: With `rpc()` + code: | + ```dart + // Only valid if the Stored Procedure returns a table type. + final data = await supabase + .rpc('echo_all_cities') + .lte('country_id', 250); + ``` + + - id: .like() + description: | + Finds all rows whose value in the stated `column` matches the supplied `pattern` (case sensitive). + $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.lte' + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('cities') + .select('name, country_id') + .like('name', '%la%'); + ``` + - id: with`update()` + name: With `update()` + code: | + ```dart + final data = await supabase + .from('cities') + .update({ 'name': 'Mordor' }) + .like('name', '%la%'); + ``` + - id: with`delete()` + name: With `delete()` + code: | + ```dart + final data = await supabase + .from('cities') + .delete() + .like('name', '%la%'); + ``` + - id: with`rpc()` + name: With `rpc()` + code: | + ```dart + // Only valid if the Stored Procedure returns a table type. + final data = await supabase + .rpc('echo_all_cities') + .like('name', '%la%'); + ``` + + - id: .ilike() + description: | + Finds all rows whose value in the stated `column` matches the supplied `pattern` (case insensitive). + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('cities') + .select('name, country_id') + .ilike('name', '%la%'); + ``` + - id: with`update()` + name: With `update()` + code: | + ```dart + final data = await supabase + .from('cities') + .update({ 'name': 'Mordor' }) + .ilike('name', '%la%'); + ``` + - id: with`delete()` + name: With `delete()` + code: | + ```dart + final data = await supabase + .from('cities') + .delete() + .ilike('name', '%la%'); + ``` + - id: with`rpc()` + name: With `rpc()` + code: | + ```dart + // Only valid if the Stored Procedure returns a table type. + final data = await supabase + .rpc('echo_all_cities') + .ilike('name', '%la%'); + ``` + + - id: .is_() + description: | + A check for exact equality (null, true, false), finds all rows whose value on the stated `column` exactly match the specified `value`. + + `is_` and `in_` filter methods are suffixed with `_` to avoid collisions with reserved keywords. + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('cities') + .select('name, country_id') + .is_('name', null); + ``` + - id: with`update()` + name: With `update()` + code: | + ```dart + final data = await supabase + .from('cities') + .update({ 'name': 'Mordor' }) + .is_('name', null); + ``` + - id: with`delete()` + name: With `delete()` + code: | + ```dart + final data = await supabase + .from('cities') + .delete() + .is_('name', null); + ``` + - id: with`rpc()` + name: With `rpc()` + code: | + ```dart + // Only valid if the Stored Procedure returns a table type. + final data = await supabase + .rpc('echo_all_cities') + .is_('name', null); + ``` + + - id: .in_() + description: | + Finds all rows whose value on the stated `column` is found on the specified `values`. + + `is_` and `in_` filter methods are suffixed with `_` to avoid collisions with reserved keywords. + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('cities') + .select('name, country_id') + .in_('name', ['Rio de Janeiro', 'San Francisco']); + ``` + - id: with`update()` + name: With `update()` + code: | + ```dart + final data = await supabase + .from('cities') + .update({ 'name': 'Mordor' }) + .in_('name', ['Rio de Janeiro', 'San Francisco']); + ``` + - id: with`delete()` + name: With `delete()` + code: | + ```dart + final data = await supabase + .from('cities') + .delete() + .in_('name', ['Rio de Janeiro', 'San Francisco']); + ``` + - id: with`rpc()` + name: With `rpc()` + code: | + ```dart + // Only valid if the Stored Procedure returns a table type. + final data = await supabase + .rpc('echo_all_cities') + .in_('name', ['Rio de Janeiro', 'San Francisco']); + ``` + + - id: .contains() + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('countries') + .select('name, id, main_exports') + .contains('main_exports', ['oil']); + ``` + - id: with`update()` + name: With `update()` + code: | + ```dart + final data = await supabase + .from('countries') + .update({ 'name': 'Mordor' }) + .contains('main_exports', ['oil']); + ``` + - id: with`delete()` + name: With `delete()` + code: | + ```dart + final data = await supabase + .from('countries') + .delete() + .contains('main_exports', ['oil']); + ``` + - id: with`rpc()` + name: With `rpc()` + code: | + ```dart + // Only valid if the Stored Procedure returns a table type. + final data = await supabase + .rpc('echo_all_countries') + .contains('main_exports', ['oil']); + ``` + + - id: .containedBy() + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('countries') + .select('name, id, main_exports') + .containedBy('main_exports', ['cars', 'food', 'machine']); + ``` + - id: with`update()` + name: With `update()` + code: | + ```dart + final data = await supabase + .from('countries') + .update({ 'name': 'Mordor' }) + .containedBy('main_exports', ['orks', 'surveillance', 'evil']); + ``` + - id: with`delete()` + name: With `delete()` + code: | + ```dart + final data = await supabase + .from('countries') + .delete() + .containedBy('main_exports', ['cars', 'food', 'machine']); + ``` + - id: with`rpc()` + name: With `rpc()` + code: | + ```dart + // Only valid if the Stored Procedure returns a table type. + final data = await supabase + .rpc('echo_all_countries') + .containedBy('main_exports', ['cars', 'food', 'machine']); + ``` + + - id: .rangeLt() + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('countries') + .select('name, id, population_range_millions') + .rangeLt('population_range_millions', '[150, 250]'); + ``` + - id: with`update()` + name: With `update()` + code: | + ```dart + final data = await supabase + .from('countries') + .update({ 'name': 'Mordor' }) + .rangeLt('population_range_millions', '[150, 250]'); + ``` + - id: with`delete()` + name: With `delete()` + code: | + ```dart + final data = await supabase + .from('countries') + .delete() + .rangeLt('population_range_millions', '[150, 250]'); + ``` + - id: with`rpc()` + name: With `rpc()` + code: | + ```dart + // Only valid if the Stored Procedure returns a table type. + final data = await supabase + .rpc('echo_all_countries') + .rangeLt('population_range_millions', '[150, 250]'); + ``` + + - id: .rangeGt() + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('countries') + .select('name, id, population_range_millions') + .rangeGt('population_range_millions', '[150, 250]'); + ``` + - id: with`update()` + name: With `update()` + code: | + ```dart + final data = await supabase + .from('countries') + .update({ 'name': 'Mordor' }) + .rangeGt('population_range_millions', '[150, 250]'); + ``` + - id: with`delete()` + name: With `delete()` + code: | + ```dart + final data = await supabase + .from('countries') + .delete() + .rangeGt('population_range_millions', '[150, 250]'); + ``` + - id: with`rpc()` + name: With `rpc()` + code: | + ```dart + // Only valid if the Stored Procedure returns a table type. + final data = await supabase + .rpc('echo_all_countries') + .rangeGt('population_range_millions', '[150, 250]'); + ``` + + - id: .rangeGte() + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('countries') + .select('name, id, population_range_millions') + .rangeGte('population_range_millions', '[150, 250]'); + ``` + - id: with`update()` + name: With `update()` + code: | + ```dart + final data = await supabase + .from('countries') + .update({ 'name': 'Mordor' }) + .rangeGte('population_range_millions', '[150, 250]'); + ``` + - id: with`delete()` + name: With `delete()` + code: | + ```dart + final data = await supabase + .from('countries') + .delete() + .rangeGte('population_range_millions', '[150, 250]'); + ``` + - id: with`rpc()` + name: With `rpc()` + code: | + ```dart + // Only valid if the Stored Procedure returns a table type. + final data = await supabase + .rpc('echo_all_countries') + .rangeGte('population_range_millions', '[150, 250]'); + ``` + + - id: .rangeLte() + $ref: '@supabase/postgrest-js.PostgrestFilterBuilder.rangeLte' + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('countries') + .select('name, id, population_range_millions') + .rangeLte('population_range_millions', '[150, 250]'); + ``` + - id: with`update()` + name: With `update()` + code: | + ```dart + final data = await supabase + .from('countries') + .update({ 'name': 'Mordor' }) + .rangeLte('population_range_millions', '[150, 250]'); + ``` + - id: with`delete()` + name: With `delete()` + code: | + ```dart + final data = await supabase + .from('countries') + .delete() + .rangeLte('population_range_millions', '[150, 250]'); + ``` + - id: with`rpc()` + name: With `rpc()` + code: | + ```dart + // Only valid if the Stored Procedure returns a table type. + final data = await supabase + .rpc('echo_all_countries') + .rangeLte('population_range_millions', [150, 250]); + ``` + + - id: .rangeAdjacent() + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('countries') + .select('name, id, population_range_millions') + .rangeAdjacent('population_range_millions', '[70, 185]'); + ``` + - id: with`update()` + name: With `update()` + code: | + ```dart + final data = await supabase + .from('countries') + .update({ 'name': 'Mordor' }) + .rangeAdjacent('population_range_millions', '[70, 185]'); + ``` + - id: with`delete()` + name: With `delete()` + code: | + ```dart + final data = await supabase + .from('countries') + .delete() + .rangeAdjacent('population_range_millions', '[70, 185]'); + ``` + - id: with`rpc()` + name: With `rpc()` + code: | + ```dart + // Only valid if the Stored Procedure returns a table type. + final data = await supabase + .rpc('echo_all_countries') + .rangeAdjacent('population_range_millions', '[70, 185]'); + ``` + + - id: .overlaps() + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('countries') + .select('name, id, main_exports') + .overlaps('main_exports', ['computers', 'minerals']); + ``` + - id: with`update()` + name: With `update()` + code: | + ```dart + final data = await supabase + .from('countries') + .update({ 'name': 'Mordor' }) + .overlaps('main_exports', ['computers', 'minerals']); + ``` + - id: with`delete()` + name: With `delete()` + code: | + ```dart + final data = await supabase + .from('countries') + .delete() + .overlaps('main_exports', ['computers', 'minerals']); + ``` + - id: with`rpc()` + name: With `rpc()` + code: | + ```dart + // Only valid if the Stored Procedure returns a table type. + final data = await supabase + .rpc('echo_all_countries') + .overlaps('main_exports', ['computers', 'minerals']); + ``` + + - id: .textSearch() + description: | + Finds all rows whose tsvector value on the stated `column` matches to_tsquery(query). + examples: + - id: text-search + name: Text search + code: | + ```dart + final data = await supabase + .from('quotes') + .select('catchphrase') + .textSearch('catchphrase', "'fat' & 'cat'", + config: 'english' + ); + ``` + - id: basic-normalization + name: Basic normalization + description: Uses PostgreSQL's `plainto_tsquery` function. + code: | + ```dart + final data = await supabase + .from('quotes') + .select('catchphrase') + .textSearch('catchphrase', "'fat' & 'cat'", + type: TextSearchType.plain, + config: 'english' + ); + ``` + - id: full-normalization + name: Full normalization + description: Uses PostgreSQL's `phraseto_tsquery` function. + code: | + ```dart + final data = await supabase + .from('quotes') + .select('catchphrase') + .textSearch('catchphrase', "'fat' & 'cat'", + type: TextSearchType.phrase, + config: 'english' + ); + ``` + - id: full-normalization + 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. + + code: | + ```dart + final data = await supabase + .from('quotes') + .select('catchphrase') + .textSearch('catchphrase', "'fat or cat'", + type: TextSearchType.websearch, + config: 'english' + ); + ``` + + - id: .filter() + description: | + Finds all rows whose `column` satisfies the filter. + notes: | + - `.filter()` expects you to use the raw [PostgREST syntax](https://postgrest.org/en/stable/api.html#horizontal-filtering-rows) for the filter names and values, so it should only be used as an escape hatch in case other filters don't work. + ```dart + .filter('arraycol','cs','{"a","b"}') // Use Postgres array {} and 'cs' for contains. + .filter('rangecol','cs','(1,2]') // Use Postgres range syntax for range column. + .filter('id','in','(6,7)') // Use Postgres list () and 'in' for in_ filter. + .filter('id','cs','{${mylist.join(',')}}') // You can insert a Dart array list. + ``` + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + code: | + ```dart + final data = await supabase + .from('cities') + .select('name, country_id') + .filter('name', 'in', '("Paris","Tokyo")'); + ``` + - id: with`update()` + name: With `update()` + code: | + ```dart + final data = await supabase + .from('cities') + .update({ 'name': 'Mordor' }) + .filter('name', 'in', '("Paris","Tokyo")'); + ``` + - id: with`delete()` + name: With `delete()` + code: | + ```dart + final data = await supabase + .from('cities') + .delete() + .filter('name', 'in', '("Paris","Tokyo")'); + ``` + - id: with`rpc()` + name: With `rpc()` + code: | + ```dart + // Only valid if the Stored Procedure returns a table type. + final data = await supabase + .rpc('echo_all_cities') + .filter('name', 'in', '("Paris","Tokyo")'); + ``` + - id: filter-embedded-resources + name: Filter embedded resources + code: | + ```dart + final data = await supabase + .from('cities') + .select('name, countries ( name )') + .filter('countries.name', 'in', '("France","Japan")'); + ``` diff --git a/spec/supabase_js_v1_temp_new_shape.yml b/spec/supabase_js_v1_temp_new_shape.yml new file mode 100644 index 00000000000..7b64c42d6be --- /dev/null +++ b/spec/supabase_js_v1_temp_new_shape.yml @@ -0,0 +1,2733 @@ +openref: 0.1 + +info: + id: reference/supabase-js + title: Supabase Client + description: | + + Supabase JavaScript. + + definition: ../../spec/enrichments/tsdoc_v1/combined.json + specUrl: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v1.yml + slugPrefix: '/' + libraries: + - name: 'JavaScript' + id: 'js' + version: '0.0.1' + +functions: + - id: auth.signUp() + title: 'signUp()' + $ref: '@supabase/gotrue-js.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.com](https://app.supabase.com) + - 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.com](https://app.supabase.com) + - If signUp() is called for an existing confirmed user: + - If "Enable email confirmations" is enabled on the "Authentication" -> "Settings" page, an obfuscated / fake user object will be returned. + - If "Enable email confirmations" is disabled, an error with a message "User already registered" will be returned. + - To check if a user already exists, refer to getUser(). + examples: + - id: sign-up. + name: Sign up. + isSpotlight: true + js: | + ```js + const { user, session, error } = await supabase.auth.signUp({ + email: 'example@email.com', + password: 'example-password', + }) + ``` + - id: sign-up-with-additional-user-meta-data. + name: Sign up with additional user meta data. + isSpotlight: true + js: | + ```js + const { user, session, error } = await supabase.auth.signUp( + { + email: 'example@email.com', + password: 'example-password', + }, + { + data: { + first_name: 'John', + age: 27, + } + } + ) + ``` + - id: sign-up-with-third-party-providers. + name: Sign up with third-party providers. + hideCodeBlock: true + description: | + You can sign up with OAuth providers using the [`signIn()`](/docs/reference/javascript/v1/auth-signin#sign-in-using-third-party-providers) method. + - id: sign-up-with-phone. + name: Sign up with Phone. + description: | + Supabase supports Phone Auth. After a user has verified their number, they can use the [`signIn()`](/docs/reference/javascript/v1/auth-signin#sign-in-using-phone) method. + js: | + ```js + const { user, session, error } = await supabase.auth.signUp({ + phone: '+13334445555', + password: 'some-password', + }) + + // After receiving an SMS with One Time Password. + let { session, error } = await supabase.auth.verifyOTP({ + phone: '+13334445555', + token: '123456', + }) + ``` + - id: auth.signIn() + title: 'signIn()' + $ref: '@supabase/gotrue-js.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.com](https://app.supabase.com) + - Specifying a `provider` will open the browser to the relevant login page. + examples: + - id: sign-in-with-email. + name: Sign in with email. + isSpotlight: true + js: | + ```js + const { user, session, error } = await supabase.auth.signIn({ + email: 'example@email.com', + password: 'example-password', + }) + ``` + - id: sign-in-with-magic-link. + 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' + }) + ``` + - id: sign-in-using-third-party-providers. + name: Sign in using third-party providers. + description: Supabase supports many different [third-party providers](https://supabase.com/docs/guides/auth#providers). + js: | + ```js + const { user, session, error } = await supabase.auth.signIn({ + // provider can be 'github', 'google', 'gitlab', and more + provider: 'github' + }) + ``` + - id: sign-in-with-phone. + name: Sign in with Phone. + description: Supabase supports Phone Auth. + js: | + ```js + const { user, session, error } = await supabase.auth.signIn({ + phone: '+13334445555', + password: 'some-password', + }) + ``` + - id: sign-in-with-redirect. + name: Sign in with redirect. + description: | + Note that the `redirectTo` param is only relevant for OAuth logins, where the login flow is managed by + the Auth server. If you are using email/phone logins you should set up your own redirects (within the email/sms template). + + 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 URL must either be on the same domain as your Site URL [see Auth>Settings in dashboard], or must match one of the Additional Redirect URLs [also in Auth>Settings]). + js: | + ```js + const { user, session, error } = await supabase.auth.signIn({ + provider: 'github' + }, { + redirectTo: 'https://example.com/welcome' + }) + ``` + - id: sign-in-with-scopes. + 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 + ``` + - id: sign-in-using-a-refresh-token(e.g.in-react-native). + 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, + }); + }); + ``` + + - id: auth.signOut() + title: 'signOut()' + $ref: '@supabase/gotrue-js.GoTrueClient.signOut' + examples: + - id: sign-out + name: Sign out + isSpotlight: true + js: | + ```js + const { error } = await supabase.auth.signOut() + ``` + + - id: auth.session() + title: 'session()' + $ref: '@supabase/gotrue-js.GoTrueClient.session' + examples: + - id: get-the-session-data + name: Get the session data + isSpotlight: true + js: | + ```js + const session = supabase.auth.session() + ``` + + - id: auth.user() + title: 'user()' + $ref: '@supabase/gotrue-js.GoTrueClient.user' + notes: | + This method gets the user object from memory. + examples: + - id: get-the-logged-in-user + name: Get the logged in user + isSpotlight: true + js: | + ```js + const user = supabase.auth.user() + ``` + + - id: auth.update() + title: 'update()' + $ref: '@supabase/gotrue-js.GoTrueClient.update' + notes: | + User email: By Default, email updates sends a confirmation link to both the user's current and new email. + To only send a confirmation link to the user's new email, disable **Secure email change** in your project's [email auth provider settings](https://app.supabase.com/project/_/auth/settings). + + User metadata: It's generally better to store user data in a table within 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: + - id: update-the-email-for-an-authenticated-user + name: Update the email for an authenticated user + description: Sends a "Confirm Email Change" email to the new email address. + isSpotlight: true + js: | + ```js + const { user, error } = await supabase.auth.update({email: 'new@email.com'}) + ``` + - id: update-the-password-for-an-authenticated-user + name: Update the password for an authenticated user + isSpotlight: true + js: | + ```js + const { user, error } = await supabase.auth.update({password: 'new password'}) + ``` + - id: update-the-user's-metadata + name: Update the user's metadata + isSpotlight: true + js: | + ```js + const { user, error } = await supabase.auth.update({ + data: { hello: 'world' } + }) + ``` + + - id: auth.setAuth() + title: 'setAuth()' + $ref: '@supabase/gotrue-js.GoTrueClient.setAuth' + examples: + - id: basic-example. + name: Basic example. + description: This is most useful on server-side functions where you cannot log the user in, but have access to the user's access token. + isSpotlight: true + js: | + ```js + function apiFunction(req, res) { + // Assuming the access token was sent as a header "X-Supabase-Auth" + const { access_token } = req.get('X-Supabase-Auth') + + // You can now use it within a Supabase Client + const supabase = createClient("https://xyzcompany.supabase.co", "public-anon-key") + const { user, error } = supabase.auth.setAuth(access_token) + + // This client will now send requests as this user + const { data } = await supabase.from('your_table').select() + } + ``` + - id: with-express. + name: With Express. + isSpotlight: true + js: | + ```js + + /** + * Make a request from the client to your server function + */ + async function makeApiRequest() { + const token = newClient.session()?.access_token + + await fetch('https://example.com/withAuth', { + method: 'GET', + withCredentials: true, + credentials: 'include', + headers: { + 'Content-Type': 'application/json', + 'Authorization': bearer, // Your own auth + 'X-Supabase-Auth': token, // Set the Supabase user + } + }) + } + + /** + * Use the Auth token in your server-side function. + */ + async function apiFunction(req, res) { + const { access_token } = req.get('X-Supabase-Auth') + + // You can now use it within a Supabase Client + const supabase = createClient("https://xyzcompany.supabase.co", "public-anon-key") + const { user, error } = supabase.auth.setAuth(access_token) + + // This client will now send requests as this user + const { data } = await supabase.from('your_table').select() + } + ``` + + - id: auth.onAuthStateChange() + title: 'onAuthStateChange()' + $ref: '@supabase/gotrue-js.GoTrueClient.onAuthStateChange' + examples: + - id: listen-to-auth-changes + name: Listen to auth changes + isSpotlight: true + js: | + ```js + supabase.auth.onAuthStateChange((event, session) => { + console.log(event, session) + }) + ``` + - id: listen-to-sign-in + name: Listen to sign in + js: | + ```js + supabase.auth.onAuthStateChange((event, session) => { + if (event == 'SIGNED_IN') console.log('SIGNED_IN', session) + }) + ``` + - id: listen-to-sign-out + name: Listen to sign out + js: | + ```js + supabase.auth.onAuthStateChange((event, session) => { + if (event == 'SIGNED_OUT') console.log('SIGNED_OUT', session) + }) + ``` + - id: listen-to-token-refresh + name: Listen to token refresh + js: | + ```js + supabase.auth.onAuthStateChange((event, session) => { + if (event == 'TOKEN_REFRESHED') console.log('TOKEN_REFRESHED', session) + }) + ``` + - id: listen-to-user-updates + name: Listen to user updates + js: | + ```js + supabase.auth.onAuthStateChange((event, session) => { + if (event == 'USER_UPDATED') console.log('USER_UPDATED', session) + }) + ``` + - id: listen-to-user-deleted + name: Listen to user deleted + js: | + ```js + supabase.auth.onAuthStateChange((event, session) => { + if (event == 'USER_DELETED') console.log('USER_DELETED', session) + }) + ``` + - id: listen-to-password-recovery-events + name: Listen to password recovery events + js: | + ```js + supabase.auth.onAuthStateChange((event, session) => { + if (event == 'PASSWORD_RECOVERY') console.log('PASSWORD_RECOVERY', session) + }) + ``` + - id: auth.api.getUser() + title: 'getUser()' + $ref: '@supabase/gotrue-js.GoTrueApi.getUser' + notes: | + - Fetches the user object from the database instead of local storage. + - Note that user() fetches the user object from local storage which might not be the most updated. + - Requires the user's access_token. + examples: + - id: fetch-the-user-object-using-the-access-token-jwt. + name: Fetch the user object using the access_token jwt. + isSpotlight: true + js: | + ```js + const { user, error } = await supabase.auth.api.getUser( + 'ACCESS_TOKEN_JWT', + ) + ``` + + - id: auth.api.listUsers() + title: 'listUsers()' + $ref: '@supabase/gotrue-js.GoTrueApi.listUsers' + notes: | + - Requires a `service_role` key. + - This function should be called on a server. Never expose your `service_role` key in the browser. + examples: + - id: get-a-full-list-of-users. + name: Get a full list of users. + isSpotlight: true + js: | + ```js + const { data: user, error } = await supabase.auth.api.listUsers() + ``` + + - id: auth.api.createUser() + title: 'createUser()' + $ref: '@supabase/gotrue-js.GoTrueApi.createUser' + notes: | + - Requires a `service_role` key. + - This function should be called on a server. Never expose your `service_role` key in the browser. + - If you do not provide the `email_confirm` and `phone_confirm` options to this function, both will default to false. + examples: + - id: create-a-new-user. + name: Create a new user. + isSpotlight: true + js: | + ```js + const { data: user, error } = await supabase.auth.api.createUser({ + email: 'user@email.com', + password: 'password', + user_metadata: { name: 'Yoda' } + }) + ``` + - id: auto-confirm-email. + name: Auto-confirm email. + isSpotlight: true + js: | + ```js + const { data: user, error } = await supabase.auth.api.createUser({ + email: 'user@email.com', + email_confirm: true + }) + ``` + - id: auto-confirm-phone. + name: Auto-confirm phone. + isSpotlight: true + js: | + ```js + const { data: user, error } = await supabase.auth.api.createUser({ + phone: '1234567890', + phone_confirm: true + }) + ``` + + - id: auth.api.deleteUser() + title: 'deleteUser()' + $ref: '@supabase/gotrue-js.GoTrueApi.deleteUser' + notes: | + - Requires a `service_role` key. + - This function should be called on a server. Never expose your `service_role` key in the browser. + examples: + - id: remove-a-user-completely. + name: Remove a user completely. + isSpotlight: true + js: | + ```js + const { data: user, error } = await supabase.auth.api.deleteUser( + '715ed5db-f090-4b8c-a067-640ecee36aa0' + ) + ``` + + - id: auth.api.inviteUserByEmail() + title: 'inviteUserByEmail()' + $ref: '@supabase/gotrue-js.GoTrueApi.inviteUserByEmail' + notes: | + - Requires a `service_role` key. + - This function should only be called on a server. Never expose your `service_role` key in the browser. + examples: + - id: basic-example. + name: Basic example. + isSpotlight: false + js: | + ```js + const { data: user, error } = await supabase.auth + .api + .inviteUserByEmail('email@example.com') + ``` + + - id: auth.api.sendMobileOTP() + title: 'sendMobileOTP()' + $ref: '@supabase/gotrue-js.GoTrueApi.sendMobileOTP' + notes: | + - Requires a `service_role` key. + - This function should only be called on a server. Never expose your `service_role` key in the browser. + examples: + - id: basic-example. + name: Basic example. + isSpotlight: false + js: | + ```js + const { data: user, error } = await supabase.auth + .api + .sendMobileOTP('12345879') + ``` + + - id: auth.api.resetPasswordForEmail() + title: 'resetPasswordForEmail()' + $ref: '@supabase/gotrue-js.GoTrueApi.resetPasswordForEmail' + notes: | + Sends a password reset request to an email address. + When the user clicks the reset link in the email they are redirected back to your application. + Prompt the user for a new password and call `auth.update()`: + ```js + const { data, error } = await supabase.auth.update({ + password: new_password, + }) + ``` + examples: + - id: reset-password + name: Reset password + isSpotlight: true + js: | + ```js + const { data, error } = await supabase.auth.api.resetPasswordForEmail( + 'user@email.com' + ) + ``` + - id: reset-password(react) + name: Reset password (React) + isSpotlight: true + js: | + ```js + /** + * Step 1: Send the user an email to get a password reset token. + * This email contains a link which sends the user back to your application. + */ + const { data, error } = await supabase.auth.api.resetPasswordForEmail( + 'user@email.com' + ) + + /** + * Step 2: Once the user is redirected back to your application, + * ask the user to reset their password. + */ + useEffect(() => { + supabase.auth.onAuthStateChange(async (event, session) => { + if (event == "PASSWORD_RECOVERY") { + const newPassword = prompt("What would you like your new password to be?"); + const { data, error } = await supabase.auth.update({ + password: newPassword, + }) + + if (data) alert("Password updated successfully!") + if (error) alert("There was an error updating your password.") + } + }) + }, []) + ``` + + - id: auth.api.generateLink() + title: 'generateLink()' + $ref: '@supabase/gotrue-js.GoTrueApi.generateLink' + notes: | + - Requires a `service_role` key. + - This function should only be called on a server. Never expose your `service_role` key in the browser. + examples: + - id: generate-an-invite-link + name: Generate an invite link + isSpotlight: false + js: | + ```js + const { data: user, error } = await supabase.auth.api.generateLink( + 'invite', + 'email@example.com' + ) + ``` + + - id: auth.api.updateUserById() + title: 'updateUserById()' + $ref: '@supabase/gotrue-js.GoTrueApi.updateUserById' + notes: | + - Requires a `service_role` key. + - This function should only be called on a server. Never expose your `service_role` key in the browser. + examples: + - id: updates-a-user's-email. + name: Updates a user's email. + isSpotlight: true + js: | + ```js + const { data: user, error } = await supabase.auth.api.updateUserById( + '6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4', + { email: 'new@email.com' } + ) + ``` + - id: updates-a-user's-password. + name: Updates a user's password. + isSpotlight: true + js: | + ```js + const { data: user, error } = await supabase.auth.api.updateUserById( + '6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4', + { password: 'new_password' } + ) + ``` + - id: updates-a-user's-metadata. + name: Updates a user's metadata. + isSpotlight: true + js: | + ```js + const { data: user, error } = await supabase.auth.api.updateUserById( + '6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4', + { user_metadata: { hello: 'world' } } + ) + ``` + - id: updates-a-user's-app-metadata. + name: Updates a user's app_metadata. + isSpotlight: true + js: | + ```js + const { data: user, error } = await supabase.auth.api.updateUserById( + '6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4', + { app_metadata: { plan: 'trial' } } + ) + ``` + - id: confirms-a-user's-email-address. + name: Confirms a user's email address. + isSpotlight: true + js: | + ```js + const { data: user, error } = await supabase.auth.api.updateUserById( + '6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4', + { email_confirm: true } + ) + ``` + - id: confirms-a-user's-phone-number. + name: Confirms a user's phone number. + isSpotlight: true + js: | + ```js + const { data: user, error } = await supabase.auth.api.updateUserById( + '6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4', + { phone_confirm: true } + ) + ``` + - id: invoke() + title: 'invoke()' + description: | + Invokes a Supabase Function. + $ref: '@supabase/functions-js.FunctionsClient.invoke' + notes: | + - Requires an Authorization header. + - Invoke params generally match the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) spec. + examples: + - id: basic-invocation. + name: Basic invocation. + isSpotlight: true + js: | + ```js + const { data, error } = await supabase.functions.invoke('hello', { + body: JSON.stringify({ foo: 'bar' }) + }) + ``` + - id: specifying-response-type. + name: Specifying response type. + description: | + By default, `invoke()` will parse the response as JSON. You can parse the response in the following formats: `json`, `blob`, `text`, and `arrayBuffer`. + isSpotlight: true + js: | + ```js + const { data, error } = await supabase.functions.invoke('hello', { + responseType: 'text', + body: JSON.stringify({ foo: 'bar' }) + }) + ``` + - id: parsing-custom-headers. + name: Parsing custom headers. + description: | + You can pass custom headers to your function. Note: supabase-js automatically passes the `Authorization` header with the signed in user's JWT. + isSpotlight: true + js: | + ```js + const { data, error } = await supabase.functions.invoke('hello', { + headers: { + "my-custom-header": 'my-custom-header-value' + }, + body: JSON.stringify({ foo: 'bar' }) + }) + ``` + + - id: 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 in 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) + - If using the Supabase hosted platform `apikey` is technically a reserved keyword, since the API gateway will pluck it out for authentication. [It should be avoided as a column name](https://github.com/supabase/supabase/issues/5465). + examples: + - id: getting-your-data + name: Getting your data + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('cities') + .select() + ``` + - id: selecting-specific-columns + name: Selecting specific columns + description: You can select specific fields from your tables. + js: | + ```js + const { data, error } = await supabase + .from('cities') + .select('name') + ``` + - id: query-foreign-tables + name: Query foreign tables + description: If your database has foreign key relationships, you can query related tables too. + js: | + ```js + const { data, error } = await supabase + .from('countries') + .select(` + name, + cities ( + name + ) + `) + ``` + note: | + What about join tables + If you're in a situation where your tables are **NOT** directly related, but instead are joined by a _join table_, + you can still use the `select()` method to query the related data. The PostgREST engine detects the relationship automatically. + For more details, [follow the link](https://postgrest.org/en/latest/api.html#embedding-through-join-tables). + - id: query-the-same-foreign-table-multiple-times + 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 ) + `) + ``` + - id: filtering-with-inner-joins + name: Filtering with inner joins + description: | + If you want to filter a table based on a child table's values you can use the `!inner()` function. For example, if you wanted + to select all rows in a `message` table which belong to a user with the `username` "Jane": + js: | + ```js + const { data, error } = await supabase + .from('messages') + .select('*, users!inner(*)') + .eq('users.username', 'Jane') + ``` + - id: querying-with-count-option + 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 } + ``` + - id: querying-json-data + 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) + ``` + - id: return-data-as-csv + 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() + ``` + - id: aborting-requests-in-flight + name: Aborting requests in-flight + description: | + You can use an [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) to abort requests. Note that `status` and `statusText` doesn't mean anything for aborted requests, since the request wasn't actually fulfilled. + js: | + ```js + const ac = new AbortController() + supabase + .from('very_big_table') + .select() + .abortSignal(ac.signal) + .then(console.log) + ac.abort() + // { + // error: { + // message: 'FetchError: The user aborted a request.', + // details: '', + // hint: '', + // code: '' + // }, + // data: null, + // body: null, + // count: null, + // status: 400, + // statusText: 'Bad Request' + // } + ``` + + - id: 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: + - id: create-a-record + name: Create a record + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('cities') + .insert([ + { name: 'The Shire', country_id: 554 } + ]) + ``` + - id: bulk-create + name: Bulk create + description: | + When running a bulk create, the operation is handled in a single transaction. If any of the inserts fail, all other operations are + rolled back. + js: | + ```js + const { data, error } = await supabase + .from('cities') + .insert([ + { name: 'The Shire', country_id: 554 }, + { name: 'Rohan', country_id: 555 }, + ]) + ``` + - id: upsert + 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 }) + ``` + + - id: 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: + - id: updating-your-data + name: Updating your data + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('cities') + .update({ name: 'Middle Earth' }) + .match({ name: 'Auckland' }) + ``` + - id: updating-json-data + 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) + ``` + + - id: upsert() + title: 'Upsert data: upsert()' + $ref: '@supabase/postgrest-js."lib/PostgrestQueryBuilder".PostgrestQueryBuilder.upsert' + notes: | + - Primary keys should 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. + - If you need to insert new data and update existing data at the same time, use [Postgres triggers](https://github.com/supabase/postgrest-js/issues/173#issuecomment-825124550). + examples: + - id: upsert-your-data + name: Upsert your data + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('messages') + .upsert({ id: 3, message: 'foo', username: 'supabot' }) + ``` + - id: bulk-upsert-your-data + name: Bulk Upsert your data + isSpotlight: false + js: | + ```js + const { data, error } = await supabase + .from('messages') + .upsert([ + { id: 3, message: 'foo', username: 'supabot' }, + { id: 4, message: 'bar', username: 'supabot' } + ]) + ``` + - id: upserting-into-tables-with-constraints + 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' }) + ``` + - id: return-the-exact-number-of-rows + 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' + }) + ``` + + - id: 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: + - id: delete-records + name: Delete records + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('cities') + .delete() + .match({ id: 666 }) + ``` + + - id: rpc() + title: 'Postgres functions: rpc()' + description: | + You can call Postgres functions as _Remote Procedure Calls_, logic in your database that you can execute from anywhere. + Functions are useful when the logic rarely changes—like for password resets and updates. + + ```sql + create or replace function hello_world() returns text as $$ + select 'Hello world'; + $$ language sql; + ``` + $ref: '@supabase/postgrest-js."lib/PostgrestRpcBuilder".PostgrestRpcBuilder.rpc' + examples: + - id: call-a-postgres-function-without-arguments + name: Call a Postgres function without arguments + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .rpc('hello_world') + ``` + - id: call-a-postgres-function-with-arguments + name: Call a Postgres function with arguments + js: | + ```js + const { data, error } = await supabase + .rpc('echo_city', { name: 'The Shire' }) + ``` + - id: bulk-processing + 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'] }) + ``` + - id: call-a-postgres-function-with-filters + name: Call a Postgres function 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') + .select('name, population') + .eq('name', 'The Shire') + ``` + - id: call-a-postgres-function-with-a-count-option + name: Call a Postgres function with a 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' }) + ``` + + - id: 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: + - id: listen-to-all-database-changes + name: Listen to all database changes + isSpotlight: true + js: | + ```js + const mySubscription = supabase + .from('*') + .on('*', payload => { + console.log('Change received!', payload) + }) + .subscribe() + ``` + - id: listening-to-a-specific-table + name: Listening to a specific table + js: | + ```js + const mySubscription = supabase + .from('countries') + .on('*', payload => { + console.log('Change received!', payload) + }) + .subscribe() + ``` + - id: listening-to-inserts + name: Listening to inserts + js: | + ```js + const mySubscription = supabase + .from('countries') + .on('INSERT', payload => { + console.log('Change received!', payload) + }) + .subscribe() + ``` + - id: listening-to-updates + 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() + ``` + - id: listening-to-deletes + 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() + ``` + - id: listening-to-multiple-events + 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() + ``` + - id: listening-to-row-level-changes + 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. + notes: | + - ``eq`` filter works with all database types as under the hood, it's casting both the filter value and the database value to the correct type and then comparing them. + js: | + ```js + const mySubscription = supabase + .from('countries:id=eq.200') + .on('UPDATE', handleRecordUpdated) + .subscribe() + ``` + + - id: removeSubscription() + title: 'removeSubscription()' + $ref: '@supabase/supabase-js.index.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: + - id: remove-a-subscription + name: Remove a subscription + isSpotlight: true + js: | + ```js + supabase.removeSubscription(mySubscription) + ``` + + - id: removeAllSubscriptions() + title: 'removeAllSubscriptions()' + $ref: '@supabase/supabase-js.index.SupabaseClient.removeAllSubscriptions' + 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: + - id: removes-all-subscriptions + name: Removes all subscriptions + isSpotlight: true + js: | + ```js + supabase.removeAllSubscriptions() + ``` + + - id: getSubscriptions() + title: 'getSubscriptions()' + $ref: '@supabase/supabase-js.index.SupabaseClient.getSubscriptions' + examples: + - id: get-all-subscriptions + name: Get all subscriptions + isSpotlight: true + js: | + ```js + const subscriptions = supabase.getSubscriptions() + ``` + + - id: storage.listBuckets() + title: 'listBuckets()' + $ref: '@supabase/storage-js."lib/StorageBucketApi".StorageBucketApi.listBuckets' + notes: | + - Policy permissions required: + - `buckets` permissions: `select` + - `objects` permissions: none + examples: + - id: list-buckets + name: List buckets + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .storage + .listBuckets() + ``` + + - id: storage.getBucket() + title: 'getBucket()' + $ref: '@supabase/storage-js."lib/StorageBucketApi".StorageBucketApi.getBucket' + notes: | + - Policy permissions required: + - `buckets` permissions: `select` + - `objects` permissions: none + examples: + - id: get-bucket + name: Get bucket + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .storage + .getBucket('avatars') + ``` + + - id: storage.createBucket() + title: 'createBucket()' + $ref: '@supabase/storage-js."lib/StorageBucketApi".StorageBucketApi.createBucket' + notes: | + - Policy permissions required: + - `buckets` permissions: `insert` + - `objects` permissions: none + examples: + - id: create-bucket + name: Create bucket + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .storage + .createBucket('avatars', { public: false }) + ``` + + - id: 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: + - id: empty-bucket + name: Empty bucket + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .storage + .emptyBucket('avatars') + ``` + - id: storage.updateBucket() + title: 'updateBucket()' + $ref: '@supabase/storage-js."lib/StorageBucketApi".StorageBucketApi.updateBucket' + notes: | + - Policy permissions required: + - `buckets` permissions: `update` + - `objects` permissions: none + examples: + - id: update-bucket + name: Update bucket + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .storage + .updateBucket('avatars', { public: false }) + ``` + + - id: 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: + - id: delete-bucket + name: Delete bucket + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .storage + .deleteBucket('avatars') + ``` + + - id: 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: + - id: upload-file + 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 + }) + ``` + - id: upload-file-using`arraybuffer`from-base64-file-data + 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' + }) + ``` + + - id: 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: + - id: update-file + 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 + }) + ``` + - id: update-file-using`arraybuffer`from-base64-file-data + 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' + }) + ``` + + - id: 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: + - id: move-file + name: Move file + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .storage + .from('avatars') + .move('public/avatar1.png', 'private/avatar2.png') + ``` + + - id: storage.from.copy() + title: 'from.copy()' + $ref: '@supabase/storage-js."lib/StorageFileApi".StorageFileApi.copy' + notes: | + - Policy permissions required: + - `buckets` permissions: none + - `objects` permissions: `insert` and `select` + examples: + - id: copy-file + name: Copy file + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .storage + .from('avatars') + .copy('public/avatar1.png', 'private/avatar2.png') + ``` + + - id: 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: + - id: create-signed-url + name: Create Signed URL + isSpotlight: true + js: | + ```js + const { signedURL, error } = await supabase + .storage + .from('avatars') + .createSignedUrl('folder/avatar1.png', 60) + ``` + + - id: storage.from.createSignedUrls() + title: 'from.createSignedUrls()' + $ref: '@supabase/storage-js."lib/StorageFileApi".StorageFileApi.createSignedUrls' + notes: | + - Policy permissions required: + - `buckets` permissions: none + - `objects` permissions: `select` + examples: + - id: create-signed-urls + name: Create Signed URLs + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .storage + .from('avatars') + .createSignedUrls(['folder/avatar1.png', 'folder/avatar2.png'], 60) + ``` + + - id: storage.from.getPublicUrl() + title: 'from.getPublicUrl()' + $ref: '@supabase/storage-js."lib/StorageFileApi".StorageFileApi.getPublicUrl' + notes: | + - The bucket needs to be set to public, either via [updateBucket()](/docs/reference/javascript/storage-updatebucket) or by going to Storage on [app.supabase.com](https://app.supabase.com), clicking the overflow menu on a bucket and choosing "Make public" + - Policy permissions required: + - `buckets` permissions: none + - `objects` permissions: none + examples: + - id: returns-the-url-for-an-asset-in-a-public-bucket + 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') + ``` + + - id: 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: + - id: download-file + name: Download file + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .storage + .from('avatars') + .download('folder/avatar1.png') + ``` + + - id: 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: + - id: delete-file + name: Delete file + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .storage + .from('avatars') + .remove(['folder/avatar1.png']) + ``` + + - id: 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: + - id: list-files-in-a-bucket + 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' }, + }) + ``` + - id: search-files-in-a-bucket + name: Search files in a bucket + js: | + ```js + const { data, error } = await supabase + .storage + .from('avatars') + .list('folder', { + limit: 100, + offset: 0, + sortBy: { column: 'name', order: 'asc' }, + search: 'jon' + }) + ``` + + - id: Using modifiers + title: 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. + + - id: limit() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.limit' + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('cities') + .select('name, country_id') + .limit(1) + ``` + - id: with-embedded-resources + 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' }) + ``` + + - id: order() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.order' + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('cities') + .select('name, country_id') + .order('id', { ascending: false }) + ``` + - id: with-embedded-resources + 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'}) + ``` + - id: ordering-multiple-columns + name: Ordering multiple columns + js: | + ```js + const { data, error } = await supabase + .from('cities') + .select('name', 'country_id') + .order('country_id', { ascending: false }) + .order('name', { ascending: false }) + ``` + - id: range() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.range' + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('cities') + .select('name, country_id') + .range(0,3) + ``` + + - id: single() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.single' + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('cities') + .select('name, country_id') + .limit(1) + .single() + ``` + + - id: maybeSingle() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.maybeSingle' + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('cities') + .select('name, country_id') + .eq('name', 'Singapore') + .maybeSingle() + ``` + + - id: Using Filters + title: 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) + ``` + + ### Conditional Chaining + + Filters can be built up one step at a time and then executed. For example: + + ```js + const filterByName = null + const filterPopLow = 1000 + const filterPopHigh = 10000 + + let query = supabase + .from('cities') + .select('name, country_id') + + if (filterByName) { query = query.eq('name', filterByName) } + if (filterPopLow) { query = query.gte('population', filterPopLow) } + if (filterPopHigh) { query = query.lt('population', filterPopHigh) } + + const { data, error } = await query + ``` + + - id: .or() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.or' + notes: | + - `.or()` expects you to use the raw [PostgREST syntax](https://postgrest.org/en/stable/api.html#horizontal-filtering-rows) for the filter names and values. + + ```js + .or('id.in.(6,7), arraycol.cs.{"a","b"}') // Use Postgres list () for in filter. Array {} for array column and 'cs' for contains. + .or(`id.in.(${arrList}),arraycol.cs.{${arr}}`) // You can insert a javascipt array for list or array on array column. + .or(`id.in.(${arrList}),rangecol.cs.[${arrRange})`) // You can insert a javascipt array for list or range on a range column. + ``` + examples: + - id: with`select()` + 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') + ``` + - id: use`or`with`and` + 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)') + ``` + - id: use`or`on-foreign-tables + 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" }) + ``` + + - id: .not() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.not' + notes: | + - `.not()` expects you to use the raw [PostgREST syntax](https://postgrest.org/en/stable/api.html#horizontal-filtering-rows) for the filter names and values. + + ```js + .not('name','eq','Paris') + .not('arraycol','cs','{"a","b"}') // Use Postgres array {} for array column and 'cs' for contains. + .not('rangecol','cs','(1,2]') // Use Postgres range syntax for range column. + .not('id','in','(6,7)') // Use Postgres list () for in filter. + .not('id','in',`(${arr})`) // You can insert a javascript array. + ``` + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('cities') + .select('name, country_id') + .not('name', 'eq', 'Paris') + ``` + - id: with`update()` + name: With `update()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .update({ name: 'Mordor' }) + .not('name', 'eq', 'Paris') + ``` + - id: with`delete()` + name: With `delete()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .delete() + .not('name', 'eq', 'Paris') + ``` + - id: with`rpc()` + 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') + ``` + + - id: .match() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.match' + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('cities') + .select('name, country_id') + .match({name: 'Beijing', country_id: 156}) + ``` + - id: with`update()` + name: With `update()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .update({ name: 'Mordor' }) + .match({name: 'Beijing', country_id: 156}) + ``` + - id: with`delete()` + name: With `delete()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .delete() + .match({name: 'Beijing', country_id: 156}) + ``` + - id: with`rpc()` + 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}) + ``` + + - id: .eq() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.eq' + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('cities') + .select('name, country_id') + .eq('name', 'The shire') + ``` + - id: with`update()` + name: With `update()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .update({ name: 'Mordor' }) + .eq('name', 'San Francisco') + ``` + - id: with`delete()` + name: With `delete()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .delete() + .eq('name', 'Mordor') + ``` + - id: with`rpc()` + 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') + ``` + + - id: .neq() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.neq' + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('cities') + .select('name, country_id') + .neq('name', 'The shire') + ``` + - id: with`update()` + name: With `update()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .update({ name: 'Mordor' }) + .neq('name', 'San Francisco') + ``` + - id: with`delete()` + name: With `delete()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .delete() + .neq('name', 'Mordor') + ``` + - id: with`rpc()` + 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') + ``` + + - id: .gt() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.gt' + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('cities') + .select('name, country_id') + .gt('country_id', 250) + ``` + - id: with`update()` + name: With `update()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .update({ name: 'Mordor' }) + .gt('country_id', 250) + ``` + - id: with`delete()` + name: With `delete()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .delete() + .gt('country_id', 250) + ``` + - id: with`rpc()` + 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) + ``` + + - id: .gte() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.gte' + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('cities') + .select('name, country_id') + .gte('country_id', 250) + ``` + - id: with`update()` + name: With `update()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .update({ name: 'Mordor' }) + .gte('country_id', 250) + ``` + - id: with`delete()` + name: With `delete()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .delete() + .gte('country_id', 250) + ``` + - id: with`rpc()` + 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) + ``` + + - id: .lt() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.lt' + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('cities') + .select('name, country_id') + .lt('country_id', 250) + ``` + - id: with`update()` + name: With `update()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .update({ name: 'Mordor' }) + .lt('country_id', 250) + ``` + - id: with`delete()` + name: With `delete()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .delete() + .lt('country_id', 250) + ``` + - id: with`rpc()` + 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) + ``` + + - id: .lte() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.lte' + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('cities') + .select('name, country_id') + .lte('country_id', 250) + ``` + - id: with`update()` + name: With `update()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .update({ name: 'Mordor' }) + .lte('country_id', 250) + ``` + - id: with`delete()` + name: With `delete()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .delete() + .lte('country_id', 250) + ``` + - id: with`rpc()` + 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) + ``` + + - id: .like() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.like' + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('cities') + .select('name, country_id') + .like('name', '%la%') + ``` + - id: with`update()` + name: With `update()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .update({ name: 'Mordor' }) + .like('name', '%la%') + ``` + - id: with`delete()` + name: With `delete()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .delete() + .like('name', '%la%') + ``` + - id: with`rpc()` + 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%') + ``` + + - id: .ilike() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.ilike' + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('cities') + .select('name, country_id') + .ilike('name', '%la%') + ``` + - id: with`update()` + name: With `update()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .update({ name: 'Mordor' }) + .ilike('name', '%la%') + ``` + - id: with`delete()` + name: With `delete()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .delete() + .ilike('name', '%la%') + ``` + - id: with`rpc()` + 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%') + ``` + + - id: .is() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.is' + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('cities') + .select('name, country_id') + .is('name', null) + ``` + - id: with`update()` + name: With `update()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .update({ name: 'Mordor' }) + .is('name', null) + ``` + - id: with`delete()` + name: With `delete()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .delete() + .is('name', null) + ``` + - id: with`rpc()` + 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) + ``` + + - id: .in() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.in' + examples: + - id: with`select()` + 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']) + ``` + - id: with`update()` + name: With `update()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .update({ name: 'Mordor' }) + .in('name', ['Rio de Janeiro', 'San Francisco']) + ``` + - id: with`delete()` + name: With `delete()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .delete() + .in('name', ['Rio de Janeiro', 'San Francisco']) + ``` + - id: with`rpc()` + 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']) + ``` + + - id: .contains() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.contains' + notes: | + - `.contains()` can work on array columns or range columns. + It is very useful for finding rows where a tag array contains all the values in the filter array. + + ```js + .contains('arraycol',["a","b"]) // You can use a javascript array for an array column + .contains('arraycol','{"a","b"}') // You can use a string with Postgres array {} for array column. + .contains('rangecol','(1,2]') // Use Postgres range syntax for range column. + .contains('rangecol',`(${arr}]`) // You can insert an array into a string. + ``` + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('countries') + .select('name, id, main_exports') + .contains('main_exports', ['oil']) + ``` + - id: with`update()` + name: With `update()` + js: | + ```js + const { data, error } = await supabase + .from('countries') + .update({ name: 'Mordor' }) + .contains('main_exports', ['oil']) + ``` + - id: with`delete()` + name: With `delete()` + js: | + ```js + const { data, error } = await supabase + .from('countries') + .delete() + .contains('main_exports', ['oil']) + ``` + - id: with`rpc()` + 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']) + ``` + + - id: .containedBy() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.containedBy' + notes: | + - `.containedBy()` can work on array columns or range columns. + + ```js + .containedBy('arraycol',["a","b"]) // You can use a javascript array for an array column + .containedBy('arraycol','{"a","b"}') // You can use a string with Postgres array {} for array column. + .containedBy('rangecol','(1,2]') // Use Postgres range syntax for range column. + .containedBy('rangecol',`(${arr}]`) // You can insert an array into a string. + ``` + examples: + - id: with`select()` + 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']) + ``` + - id: with`update()` + name: With `update()` + js: | + ```js + const { data, error } = await supabase + .from('countries') + .update({ name: 'Mordor' }) + .containedBy('main_exports', ['orks', 'surveillance', 'evil']) + ``` + - id: with`delete()` + name: With `delete()` + js: | + ```js + const { data, error } = await supabase + .from('countries') + .delete() + .containedBy('main_exports', ['cars', 'food', 'machine']) + ``` + - id: with`rpc()` + 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']) + ``` + + - id: .rangeLt() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.rangeLt' + examples: + - id: with`select()` + 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]') + ``` + - id: with`update()` + name: With `update()` + js: | + ```js + const { data, error } = await supabase + .from('countries') + .update({ name: 'Mordor' }) + .rangeLt('population_range_millions', '[150, 250]') + ``` + - id: with`delete()` + name: With `delete()` + js: | + ```js + const { data, error } = await supabase + .from('countries') + .delete() + .rangeLt('population_range_millions', '[150, 250]') + ``` + - id: with`rpc()` + 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]') + ``` + + - id: .rangeGt() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.rangeGt' + examples: + - id: with`select()` + 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]') + ``` + - id: with`update()` + name: With `update()` + js: | + ```js + const { data, error } = await supabase + .from('countries') + .update({ name: 'Mordor' }) + .rangeGt('population_range_millions', '[150, 250]') + ``` + - id: with`delete()` + name: With `delete()` + js: | + ```js + const { data, error } = await supabase + .from('countries') + .delete() + .rangeGt('population_range_millions', '[150, 250]') + ``` + - id: with`rpc()` + 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]') + ``` + + - id: .rangeGte() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.rangeGte' + examples: + - id: with`select()` + 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]') + ``` + - id: with`update()` + name: With `update()` + js: | + ```js + const { data, error } = await supabase + .from('countries') + .update({ name: 'Mordor' }) + .rangeGte('population_range_millions', '[150, 250]') + ``` + - id: with`delete()` + name: With `delete()` + js: | + ```js + const { data, error } = await supabase + .from('countries') + .delete() + .rangeGte('population_range_millions', '[150, 250]') + ``` + - id: with`rpc()` + 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]') + ``` + + - id: .rangeLte() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.rangeLte' + examples: + - id: with`select()` + 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]') + ``` + - id: with`update()` + name: With `update()` + js: | + ```js + const { data, error } = await supabase + .from('countries') + .update({ name: 'Mordor' }) + .rangeLte('population_range_millions', '[150, 250]') + ``` + - id: with`delete()` + name: With `delete()` + js: | + ```js + const { data, error } = await supabase + .from('countries') + .delete() + .rangeLte('population_range_millions', '[150, 250]') + ``` + - id: with`rpc()` + 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]') + ``` + + - id: .rangeAdjacent() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.rangeAdjacent' + examples: + - id: with`select()` + 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]') + ``` + - id: with`update()` + name: With `update()` + js: | + ```js + const { data, error } = await supabase + .from('countries') + .update({ name: 'Mordor' }) + .rangeAdjacent('population_range_millions', '[70, 185]') + ``` + - id: with`delete()` + name: With `delete()` + js: | + ```js + const { data, error } = await supabase + .from('countries') + .delete() + .rangeAdjacent('population_range_millions', '[70, 185]') + ``` + - id: with`rpc()` + 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]') + ``` + + - id: .overlaps() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.overlaps' + notes: | + - `.overlaps()` can work on array columns or range columns. + + ```js + .overlaps('arraycol',["a","b"]) // You can use a javascript array for an array column + .overlaps('arraycol','{"a","b"}') // You can use a string with Postgres array {} for array column. + .overlaps('rangecol','(1,2]') // Use Postgres range syntax for range column. + .overlaps('rangecol',`(${arr}]`) // You can insert an array into a string. + ``` + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('countries') + .select('name, id, main_exports') + .overlaps('main_exports', ['computers', 'minerals']) + ``` + - id: with`update()` + name: With `update()` + js: | + ```js + let countries = await supabase + .from('countries') + .update({ name: 'Mordor' }) + .overlaps('main_exports', ['computers', 'minerals']) + ``` + - id: with`delete()` + name: With `delete()` + js: | + ```js + const { data, error } = await supabase + .from('countries') + .delete() + .overlaps('main_exports', ['computers', 'minerals']) + ``` + - id: with`rpc()` + 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']) + ``` + + - id: .textSearch() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.textSearch' + examples: + - id: text-search + name: Text search + js: | + ```js + const { data, error } = await supabase + .from('quotes') + .select('catchphrase') + .textSearch('catchphrase', `'fat' & 'cat'`, { + config: 'english' + }) + ``` + - id: basic-normalization + 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' + }) + ``` + - id: full-normalization + 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' + }) + ``` + - id: websearch + name: Websearch + 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' + }) + ``` + + - id: .filter() + $ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.filter' + notes: | + - `.filter()` expects you to use the raw [PostgREST syntax](https://postgrest.org/en/stable/api.html#horizontal-filtering-rows) for the filter names and values, so it should only be used as an escape hatch in case other filters don't work. + ```js + .filter('arraycol','cs','{"a","b"}') // Use Postgres array {} for array column and 'cs' for contains. + .filter('rangecol','cs','(1,2]') // Use Postgres range syntax for range column. + .filter('id','in','(6,7)') // Use Postgres list () for in filter. + .filter('id','in',`(${arr})`) // You can insert a javascript array. + ``` + examples: + - id: with`select()` + name: With `select()` + isSpotlight: true + js: | + ```js + const { data, error } = await supabase + .from('cities') + .select('name, country_id') + .filter('name', 'in', '("Paris","Tokyo")') + ``` + - id: with`update()` + name: With `update()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .update({ name: 'Mordor' }) + .filter('name', 'in', '("Paris","Tokyo")') + ``` + - id: with`delete()` + name: With `delete()` + js: | + ```js + const { data, error } = await supabase + .from('cities') + .delete() + .filter('name', 'in', '("Paris","Tokyo")') + ``` + - id: with`rpc()` + 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', 'in', '("Paris","Tokyo")') + ``` + - id: filter-embedded-resources + name: Filter embedded resources + js: | + ```js + const { data, error } = await supabase + .from('cities') + .select('name, countries ( name )') + .filter('countries.name', 'in', '("France","Japan")') + ``` diff --git a/spec/supabase_js_v2_temp_new_shape.yml b/spec/supabase_js_v2_temp_new_shape.yml index 29da1f13dde..97f437a1ebf 100644 --- a/spec/supabase_js_v2_temp_new_shape.yml +++ b/spec/supabase_js_v2_temp_new_shape.yml @@ -1954,6 +1954,7 @@ functions: hideCodeBlock: true - id: Using Filters + title: Using Filters description: | Filters allow you to only return rows that match certain conditions. @@ -4074,6 +4075,7 @@ functions: ``` - id: Using Modifiers + title: Using Modifiers description: | Filters work on the row level—they allows you to return rows that only match certain conditions without changing the shape of the rows.