Skip to content

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

docs: add conditional chaining to filters

vluna404f95f32b80
diff --git a/web/spec/supabase.yml b/web/spec/supabase.yml
index d9d6124e714..73ce9098ec5 100644
--- a/web/spec/supabase.yml
+++ b/web/spec/supabase.yml
@@ -1689,6 +1689,26 @@ pages:
.lt('population', 10000)
```
+ ### Conditionally 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
+ ```
+
.or():
$ref: '@supabase/postgrest-js."lib/PostgrestFilterBuilder".PostgrestFilterBuilder.or'
examples: