The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Cleans up a lot of issues covered in #9. Specifically:
Copple0713fdfba49e
diff --git a/web/docs/common/filters/filter.mdx b/web/docs/common/filters/filter.mdxindex 0d798d4ef06..ceba93bd9ba 100644--- a/web/docs/common/filters/filter.mdx+++ b/web/docs/common/filters/filter.mdx@@ -7,7 +7,7 @@ supabase.filter(columnName, operator, criteria)```-All in one convenience function for all filters available.+This allows you to apply various filters on your query. Filters can also be chained together.<Collapsable title="Toggle Example">@@ -15,9 +15,8 @@ All in one convenience function for all filters available.```js {3-5}supabase.from('countries')- .filter('name', 'in', '['China', 'France']')- .filter('name', 'like', '%n%')- .filter('id', 'gte', 20)+ .filter('name', 'in', '["China", "France"]')+ .filter('status', 'eq', 'ACTIVE')```</Collapsable>diff --git a/web/docs/library/get.mdx b/web/docs/library/get.mdxindex 66d6bfe4a6b..5ce6c3aad6a 100644--- a/web/docs/library/get.mdx+++ b/web/docs/library/get.mdx@@ -10,164 +10,190 @@ import CommonResponses from '../common/CommonResponses.mdx'import Collapsable from '../../src/components/Collapsable'import FromFunction from '../common/FromFunction.mdx'import DummyData from '../common/DummyData.mdx'+import CustomCodeBlock from '../../src/components/CustomCodeBlock'+import { getSimpleJs, getColumnsJs, getForeignJs, getForeignMultipleJs } from './getExamples'<DummyData />### Getting your data-This example shows how to get all the countries in our database:+<CustomCodeBlock+ header="Shows how to get all countries from our public 'world' database"+ js={getSimpleJs}+ jsHighlight="{7-9}"+ response={`{+ body: [+ { "name": "Rio de Janeiro", "country_id": 76 },+ { "name": "Beijing", "country_id": 156 },+ { "name": "Paris", "country_id": 250 },+ { "name": "Auckland", "country_id": 554 },+ { "name": "Lagos", "country_id": 556 },+ { "name": "San Francisco", "country_id": 840 }+ ],+ status: 200,+ statusCode: 200,+ statusText: "OK"+}`}+/>-<!-- prettier-ignore -->-```js {7-9}-import { createClient } from '@supabase/supabase-js'--const supabase = createClient('https://world.supabase.co', '1a2b-3c4d-5e6f-7g8h')--const getCities = async () => {- try {- let cities = await supabase- .from('cities')- .select('*')- return cities- } catch (error) {- console.log('Error: ', error)- }-}-```--<Collapsable title="Toggle Example Response">--Calling `getCities()` will return the following response:--```json-[- { "name": "Rio de Janeiro", "country_id": 76 },- { "name": "Beijing", "country_id": 156 },- { "name": "Paris", "country_id": 250 },- { "name": "Auckland", "country_id": 554 },- { "name": "Lagos", "country_id": 556 },- { "name": "San Francisco", "country_id": 840 }-]-```-</Collapsable>### Getting specific columns-This example shows how to get all cities but only return the name:--<!-- prettier-ignore -->-```js {9}-import { createClient } from '@supabase/supabase-js'--const supabase = createClient('https://world.supabase.co', '1a2b-3c4d-5e6f-7g8h')--const getCities = async () => {- try {- let cities = await supabase- .from('cities')- .select('name')- return cities- } catch (error) {- console.log('Error: ', error)- }-}-```+<CustomCodeBlock+ header="Shows how to get all cities but only return the name"+ js={getColumnsJs}+ jsHighlight="{9}"+ response={`{+ body: [+ { "name": "Rio de Janeiro" },+ { "name": "Beijing" },+ { "name": "Paris" },+ { "name": "Auckland" },+ { "name": "Lagos" },+ { "name": "San Francisco" }+ ],+ status: 200,+ statusCode: 200,+ statusText: "OK"+}`}+/>-<Collapsable title="Toggle Example Response">--Calling `getCities()` will return the following response:--```json-[- { "name": "Rio de Janeiro" },- { "name": "Beijing" },- { "name": "Paris" },- { "name": "Auckland" },- { "name": "Lagos" },- { "name": "San Francisco" }-]-```--</Collapsable>### Query foreign tables+<CustomCodeBlock+ header="Shows how to get all countries and the name of each of their cities"+ js={getForeignJs}+ jsHighlight="{9-14}"+ response={`{+ body: [+ {+ "name": "Brazil",+ "cities": [+ { "name": "Rio de Janeiro" }+ ]+ },+ {+ "name": "China",+ "cities": [+ { "name": "Beijing" }+ ]+ },+ {+ "name": "France",+ "cities": [+ { "name": "Paris" }+ ]+ },+ {+ "name": "New Zealand",+ "cities": [+ { "name": "Auckland" }+ ]+ },+ {+ "name": "Nigeria",+ "cities": [+ { "name": "Lagos" }+ ]+ },+ {+ "name": "United States",+ "cities": [+ { "name": "San Francisco" }+ ]+ }+ ],+ status: 200,+ statusCode: 200,+ statusText: "OK"+}`}+/>-This example shows how to get all countries and the cities their cities:--<!-- prettier-ignore -->-```js {9-14}-import { createClient } from '@supabase/supabase-js'--const supabase = createClient('https://world.supabase.co', '1a2b-3c4d-5e6f-7g8h')--const getCountries = async () => {- try {- let countries = await supabase- .from('countries')- .select(`- name,- cities (- name- )- `)- return countries- } catch (error) {- console.log('Error: ', error)- }-}-```-+### Query foreign tables+<CustomCodeBlock+ header="Shows how to get all countries and the name of each of their cities"+ js={getForeignJs}+ jsHighlight="{9-14}"+ response={`{+ body: [+ {+ "name": "Brazil",+ "cities": [+ { "name": "Rio de Janeiro" }+ ]+ },+ {+ "name": "China",+ "cities": [+ { "name": "Beijing" }+ ]+ },+ {+ "name": "France",+ "cities": [+ { "name": "Paris" }+ ]+ },+ {+ "name": "New Zealand",+ "cities": [+ { "name": "Auckland" }+ ]+ },+ {+ "name": "Nigeria",+ "cities": [+ { "name": "Lagos" }+ ]+ },+ {+ "name": "United States",+ "cities": [+ { "name": "San Francisco" }+ ]+ }+ ],+ status: 200,+ statusCode: 200,+ statusText: "OK"+}`}+/>++### Query the same foreign table multiple times++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:+++<CustomCodeBlock+ header="Shows how to reference a foreign table when it is referenced twice"+ js={getForeignMultipleJs}+ jsHighlight="{9-13}"+ response={`{+ body: [+ {+ "id": 1,+ "purchaser": { "name": "John" },+ "supplier": { "name": "Jane" }+ },+ {+ "id": 2,+ "purchaser": { "name": "Sue" },+ "supplier": { "name": "Steve" }+ }+ ],+ status: 200,+ statusCode: 200,+ statusText: "OK"+}`}+/>-<Collapsable title="Toggle Example Response">--Calling `getCountries()` will return the following response:--```json-[- {- "name": "Brazil",- "cities": [- { "name": "Rio de Janeiro" }- ]- },- {- "name": "China",- "cities": [- { "name": "Beijing" }- ]- },- {- "name": "France",- "cities": [- { "name": "Paris" }- ]- },- {- "name": "New Zealand",- "cities": [- { "name": "Auckland" }- ]- },- {- "name": "Nigeria",- "cities": [- { "name": "Lagos" }- ]- },- {- "name": "United States",- "cities": [- { "name": "San Francisco" }- ]- }-]-```-</Collapsable>## Referencediff --git a/web/docs/library/getExamples.js b/web/docs/library/getExamples.jsnew file mode 100644index 00000000000..bd9278cfae1--- /dev/null+++ b/web/docs/library/getExamples.js@@ -0,0 +1,77 @@++export const getSimpleJs = `+import { createClient } from '@supabase/supabase-js'++const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')++const getCities = async () => {+ try {+ let cities = await supabase+ .from('cities')+ .select('*')+ return cities+ } catch (error) {+ console.log('Error: ', error)+ }+}+`++export const getColumnsJs = `+import { createClient } from '@supabase/supabase-js'++const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')++const getCities = async () => {+ try {+ let cities = await supabase+ .from('cities')+ .select('name')+ return cities+ } catch (error) {+ console.log('Error: ', error)+ }+}+`++export const getForeignJs = `+import { createClient } from '@supabase/supabase-js'++const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')++const getCountries = async () => {+ try {+ let countries = await supabase+ .from('countries')+ .select(\`+ name,+ cities (+ name+ )+ \`)+ return countries+ } catch (error) {+ console.log('Error: ', error)+ }+}+`++export const getForeignMultipleJs = `+import { createClient } from '@supabase/supabase-js'++const supabase = createClient('https://shop.supabase.co', 'public-key-bOYapLADERfE')++const getProducts = async () => {+ try {+ let products = await supabase+ .from('products')+ .select(\`+ id,+ supplier:supplier_id ( name ),+ purchaser:purchaser_id ( name )+ \`)+ return products+ } catch (error) {+ console.log('Error: ', error)+ }+}+`\ No newline at end of filediff --git a/web/src/components/CustomCodeBlock.js b/web/src/components/CustomCodeBlock.jsindex e1d5440679d..a5a4c40a217 100644--- a/web/src/components/CustomCodeBlock.js+++ b/web/src/components/CustomCodeBlock.js@@ -1,15 +1,55 @@import 'react-perfect-scrollbar/dist/css/styles.css'-import React from 'react'+import React, { useState } from 'react'import CodeBlock from '@theme/CodeBlock'import PerfectScrollbar from 'react-perfect-scrollbar'-export default function CustomCodeBlock({ header, js }) {+export default function CustomCodeBlock({ header, js, jsHighlight, response }) {+ const [showResponse, toggleResponse] = useState(false)++ let wrapperClass = ''+ if (header) wrapperClass += ' code-with-header'+ if (response) wrapperClass += ' code-with-response'+return (- <div className={header ? 'code-with-header' : ''}>- {header && <div className="code-header">{header}</div>}- <PerfectScrollbar>- <CodeBlock>{js}</CodeBlock>- </PerfectScrollbar>- </div>+ <>+ <div className={wrapperClass}>+ {header && <div className="code-header">{header}</div>}+ <PerfectScrollbar>+ <CodeBlock metastring={jsHighlight}>{js}</CodeBlock>+ </PerfectScrollbar>+ </div>+ {response && (+ <>+ <div className={'code-with-header'}>+ <a+ className="code-header has-hover-pointer"+ style={showResponse ? styles.responseShown : styles.responseHidden}+ onClick={() => toggleResponse(!showResponse)}+ >+ {showResponse ? 'Hide' : 'Show'} Response+ </a>+ {showResponse && <CodeBlock>{response}</CodeBlock>}+ </div>+ </>+ )}+ </>)}++const styles = {+ responseShown: {+ textAlign: 'right',+ display: 'block',+ borderRadius: '0',+ color: 'var(--custom-primary)',+ borderTop: '1px solid #444'+ },+ responseHidden: {+ textAlign: 'right',+ display: 'block',+ borderBottom: 'none',+ borderRadius: '0 0 4px 4px',+ borderTop: '1px solid #444',+ color: '#ccc'+ },+}diff --git a/web/src/css/custom.css b/web/src/css/custom.cssindex 2b6a142e998..2f03a4e4dc4 100755--- a/web/src/css/custom.css+++ b/web/src/css/custom.css@@ -542,6 +542,9 @@ div[class^='sidebar_'] .menu__link.menu__link--active:not(.menu__link--sublist).code-with-header pre {border-radius: 0 0 4px 4px;}+.code-with-response pre {+ border-radius: 0;+}.code-header {background: var(--ifm-code-background-dark);color: #ccc;@@ -674,4 +677,8 @@ a.hash-link {margin-top: var(--ifm-spacing-horizontal) !important;margin-bottom: var(--ifm-spacing-horizontal) !important;}+}++.has-hover-pointer:hover {+ cursor: pointer;}\ No newline at end of filediff --git a/web/src/pages/index.js b/web/src/pages/index.jsindex fdbde7c26c3..b6dbbc77212 100755--- a/web/src/pages/index.js+++ b/web/src/pages/index.js@@ -5,7 +5,6 @@ import Link from '@docusaurus/Link'import useDocusaurusContext from '@docusaurus/useDocusaurusContext'import useBaseUrl from '@docusaurus/useBaseUrl'import styles from './styles.module.css'-import CodeBlock from '@theme/CodeBlock'import CustomCodeBlock from '../components/CustomCodeBlock'const heroExample = `