Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

added sql-to-api

Mark Burggraf1de0477510f4
diff --git a/web/docs/guides/database/sql-to-api.mdx b/web/docs/guides/database/sql-to-api.mdx
new file mode 100644
index 00000000000..e9787ef4fdd
--- /dev/null
+++ b/web/docs/guides/database/sql-to-api.mdx
@@ -0,0 +1,70 @@
+---
+id: sql-to-api
+title: "Converting SQL to Javascript API"
+description: Implementing common SQL patterns in the Javascript API
+---
+
+import Tabs from '@theme/Tabs';
+import TabItem from '@theme/TabItem';
+
+Select a set of columns from a single table with where, order by, and limit clauses.
+
+```sql
+select first_name, last_name, team_id, age from players
+where age between 20 and 24 and team_id <> 'STL'
+order by last_name, first_name desc
+limit 20
+```
+
+```js
+const { data, error } = await supabase
+.from('players')
+.select('first_name,last_name,team_id,age')
+.gte('age', 20)
+.lte('age', 24)
+.not('team_id', 'eq', 'STL')
+.order('last_name', { ascending: true }) // or just .order('last_name')
+.order('first_name', { ascending: false })
+.limit(20)
+```
+
+Select all columns from a single table with a complex where clause: OR AND OR
+
+```sql
+select * from players
+where ((team_id = 'CHN' or team_id is null) and (age > 35 or age is null))
+```
+
+```js
+const { data, error } = await supabase
+.from('players')
+.select() // or .select('*')
+.or('team_id.eq.CHN,team_id.is.null')
+.or('age.gt.35,age.is.null) // additional filters imply "AND"
+.not('team_id', 'eq', 'STL')
+```
+
+Select all columns from a single table with a complex where clause: AND OR AND
+
+```sql
+select * from players
+where ((team_id = 'CHN' and age > 35) or (team_id <> 'CHN and age is not null))
+```
+
+```js
+const { data, error } = await supabase
+.from('players')
+.select() // or .select('*')
+.or('and(team_id.eq.CHN,age.gt.35),and(team_id.neq.CHN,.not.age.is.null)')
+```
+
+
+## Resources
+
+* [Supabase Account - Free Tier OK](https://supabase.io)
+* [Postgrest Operators](https://postgrest.org/en/stable/api.html#operators)
+* [Supabase Javascript API: select](https://supabase.io/docs/reference/javascript/select)
+* [Supabase Javascript API: modifiers](https://supabase.io/docs/reference/javascript/using-modifiers)
+* [Supabase Javascript API: filters](https://supabase.io/docs/reference/javascript/using-filters)
+
+
diff --git a/web/sidebars.js b/web/sidebars.js
index ad2d1eea4cf..a2c7f3e8c49 100755
--- a/web/sidebars.js
+++ b/web/sidebars.js
@@ -112,11 +112,12 @@ module.exports = {
'guides/database/arrays',
'guides/database/json',
'guides/database/password-reset',
+ 'guides/database/sql-to-api',
{
type: 'category',
- label: 'Auth Deep Dive',
+ label: 'SQL Tutorial',
collapsed: false,
- items: ['guides/auth/auth-apple'],
+ items: ['guides/database/arrays'],
},
],
},