The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Adds v2 text
Copple33e03ec7e10d
diff --git a/apps/reference/_supabase_js/initializing.mdx b/apps/reference/_supabase_js/initializing.mdxnew file mode 100644index 00000000000..b6844ce57aa--- /dev/null+++ b/apps/reference/_supabase_js/initializing.mdx@@ -0,0 +1,211 @@+---+id: initializing+title: "Initializing"+slug: initializing+custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/supabase.yml+---++import Tabs from '@theme/Tabs';+import TabItem from '@theme/TabItem';++You can initialize a new Supabase client using the `createClient()` method.++The Supabase client is your entrypoint to the rest of the Supabase functionality+and is the easiest way to interact with everything we offer within the Supabase ecosystem.+++++## Parameters+++<ul className="method-list-group">++<li className="method-list-item">+ <h4 className="method-list-item-label">+ <span className="method-list-item-label-name">+ supabaseUrl+ </span>+ <span className="method-list-item-label-badge required">+ required+ </span>+ <span className="method-list-item-validation">+ <code>string</code>+ </span>+ </h4>+ <div class="method-list-item-description">++The unique Supabase URL which is supplied when you create a new project in your project dashboard.++ </div>++</li>+++<li className="method-list-item">+ <h4 className="method-list-item-label">+ <span className="method-list-item-label-name">+ supabaseKey+ </span>+ <span className="method-list-item-label-badge required">+ required+ </span>+ <span className="method-list-item-validation">+ <code>string</code>+ </span>+ </h4>+ <div class="method-list-item-description">++The unique Supabase Key which is supplied when you create a new project in your project dashboard.++ </div>++</li>+++<li className="method-list-item">+ <h4 className="method-list-item-label">+ <span className="method-list-item-label-name">+ options+ </span>+ <span className="method-list-item-label-badge false">+ optional+ </span>+ <span className="method-list-item-validation">+ <code>SupabaseClientOptions</code>+ </span>+ </h4>+ <div class="method-list-item-description">++No description provided.++ </div>++</li>++</ul>+++++++++++++++## Examples++### createClient()++++<Tabs+ defaultValue="js"+ groupId="reference/supabase-js"+ values={[{ label: 'JavaScript', value: 'js' }]}>++<TabItem value="js">++```js+import { createClient } from '@supabase/supabase-js'++// Create a single supabase client for interacting with your database+const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key')+```+++</TabItem>++</Tabs>++### With additional parameters++++<Tabs+ defaultValue="js"+ groupId="reference/supabase-js"+ values={[{ label: 'JavaScript', value: 'js' }]}>++<TabItem value="js">++```js+import { createClient } from '@supabase/supabase-js'++const options = {+ schema: 'public',+ headers: { 'x-my-custom-header': 'my-app-name' },+ autoRefreshToken: true,+ persistSession: true,+ detectSessionInUrl: true+}+const supabase = createClient("https://xyzcompany.supabase.co", "public-anon-key", options)+```+++</TabItem>++</Tabs>++### API schemas++++<Tabs+ defaultValue="js"+ groupId="reference/supabase-js"+ values={[{ label: 'JavaScript', value: 'js' }]}>++<TabItem value="js">++```js+import { createClient } from '@supabase/supabase-js'++// Provide a custom schema. Defaults to "public".+const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key', {+ schema: 'other_schema'+})+```++By default the API server points to the `public` schema. You can enable other database schemas within the Dashboard.+Go to `Settings > API > Schema` and add the schema which you want to expose to the API.++Note: each client connection can only access a single schema, so the code above can access the `other_schema` schema but cannot access the `public` schema.+++</TabItem>++</Tabs>++### Custom `fetch` implementation++++<Tabs+ defaultValue="js"+ groupId="reference/supabase-js"+ values={[{ label: 'JavaScript', value: 'js' }]}>++<TabItem value="js">++```js+import { createClient } from '@supabase/supabase-js'++const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key', {+ fetch: fetch.bind(globalThis)+})+```++`supabase-js` uses the [`cross-fetch`](https://www.npmjs.com/package/cross-fetch) library to make HTTP requests,+but an alternative `fetch` implementation can be provided as an option.+This is most useful in environments where `cross-fetch` is not compatible (for instance Cloudflare Workers).+++</TabItem>++</Tabs>\ No newline at end of filediff --git a/apps/reference/_supabase_js/installing.mdx b/apps/reference/_supabase_js/installing.mdxnew file mode 100644index 00000000000..cb6372c7d8b--- /dev/null+++ b/apps/reference/_supabase_js/installing.mdx@@ -0,0 +1,34 @@+---+id: installing+title: "Installing"+slug: installing+custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/supabase.yml+---++import Tabs from '@theme/Tabs';+import TabItem from '@theme/TabItem';++All JavaScript libraries are built directly by the Supabase team.++Other languages are built by the community and supported by Supabase.++## JavaScript++Via NPM+```bash+npm install @supabase/supabase-js+```++Via Yarn+```bash+yarn add @supabase/supabase-js+```++Find the source code on [GitHub](https://github.com/supabase/supabase-js).++Or via CDN+```js+<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js"></script>+//or+<script src="https://unpkg.com/@supabase/supabase-js"></script>+```\ No newline at end of filediff --git a/apps/reference/_supabase_js/working-with-types.md b/apps/reference/_supabase_js/working-with-types.mdindex 5c768ce174f..b2a95a79958 100644--- a/apps/reference/_supabase_js/working-with-types.md+++ b/apps/reference/_supabase_js/working-with-types.md@@ -4,4 +4,90 @@ id: typescript-support# Typescript Support-Some type information here.+`supabase-js` supports Typescript.+++## Generating types++You can use our CLI to generate types:++```bash+supabase start+supabase gen types typescript --local > lib/database.types.ts+```++These types are generated directly from your database. Given a table `public.movies`, the definition will provide the following data:++```ts++interface Database {+ public: {+ Tables: {+ movies: {+ Row: {} // The data expected to be returned from a "select" statement.+ Insert: {} // The data expected passed to an "insert" statement.+ Update: {} // The data expected passed to an "update" statement.+ }+ }+ }+}++```++There is a different between `selects`, `inserts`, and `updates`, because often you will set default values in your database for specific columns.+With default values you do not need to send any data over the network, even if that column is a "required" field. Our type system is granular+enough to handle these situations.+++## Injecting type definitions++You can enrich the supabase client with the types you generated with Supabase.++```ts+import { createClient } from "@supabase/supabase-js"+import { Database } from "lib/database.types"++const supabase = createClient<Database>(+ process.env.SUPABASE_URL,+ process.env.SUPABASE_ANON_KEY+)+```++## Type hints++`supabase-js` always returns a `data` object (for success), and an `error` response (for unsuccessful requests).+This provides a simple interface to get the relevant types returned from any function:+++```ts+export async function getMovies() {+ return await supabase.from("movies")+ .select(`id, title`)+}++type MoviesResponse = Awaited<ReturnType<typeof getMovies>>+export type MoviesResponseSuccess = MoviesResponse["data"]+export type MoviesResponseError = MoviesResponse["error"]+```++## Nested tables++For advanced queries such as nested tables, you may want to construct your own types.++```ts+import supabase from "~/lib/supabase"+import type { Database } from "~/lib/database.types"+++async function getMovies() {+ return await supabase.from('movies')+ .select('id, title, actors(*)')+}+++type actors = Database["public"]["Tables"]["actors"]["Row"]+type MoviesResponse = Awaited<ReturnType<typeof getMovies>>+type MoviesResponseSuccess = MoviesResponse["data"] & {+ actors: actors[]+}+```\ No newline at end of filediff --git a/apps/reference/nav/supabase_js_sidebars.js b/apps/reference/nav/supabase_js_sidebars.jsindex 17bb4f52095..2dc9b8d80f9 100644--- a/apps/reference/nav/supabase_js_sidebars.js+++ b/apps/reference/nav/supabase_js_sidebars.js@@ -22,9 +22,11 @@ const sidebars = {label: 'Getting Started',items: ['intro',- 'migration-guide',- 'release-notes',+ 'installing',+ 'initializing','typescript-support',+ 'release-notes',+ 'migration-guide',],collapsed: false,},