Skip to content

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

feat: Done with postgrest

dshukertjr05ca6c93726a
diff --git a/web/spec/dart.yml b/web/spec/dart.yml
index 53e0246bb29..85c366500c0 100644
--- a/web/spec/dart.yml
+++ b/web/spec/dart.yml
@@ -30,14 +30,14 @@ info:
- auth.update()
- auth.onAuthStateChange()
- Reset Password (Email)
- # - name: 'Data'
- # items:
- # - select()
- # - insert()
- # - update()
- # - upsert()
- # - delete()
- # - rpc()
+ - name: 'Data'
+ items:
+ - select()
+ - insert()
+ - update()
+ - upsert()
+ - delete()
+ - rpc()
# - name: 'Realtime'
# items:
# - subscribe()
@@ -237,8 +237,8 @@ pages:
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
+ dart: |
+ ```dart
const { user, session, error } = await supabase.auth.signIn({
provider: 'github'
}, {
@@ -344,3 +344,266 @@ pages:
final error = res.error;
```
+ select():
+ title: 'Fetch data: select()'
+ notes: |
+ - By default, Supabase projects will return a maximum of 1,000 rows. This setting can be changed 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.
+ TODO change the followinng links to dart
+ - `select()` can be combined with [Modifiers](/docs/reference/javascript/using-modifiers)
+ - `select()` can be combined with [Filters](/docs/reference/javascript/using-filters)
+ examples:
+ - name: Getting your data
+ isSpotlight: true
+ dart: |
+ ```dart
+ final res = await supabase
+ .from('cities')
+ .select()
+ .execute();
+
+ final data = res.data;
+ final error = res.error;
+ ```
+ - name: Selecting specific columns
+ description: You can select specific fields from your tables.
+ dart: |
+ ```dart
+ final res = await supabase
+ .from('cities')
+ .select('name')
+ .execute();
+ ```
+ - name: Query foreign tables
+ description: If your database has relationships, you can query related tables too.
+ dart: |
+ ```dart
+ final res = await supabase
+ .from('countries')
+ .select('''
+ name,
+ cities (
+ name
+ )
+ ''')
+ .execute();
+ ```
+ - 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:
+ dart: |
+ ```dart
+ final res = await supabase
+ .from('products')
+ .select('''
+ id,
+ supplier:supplier_id ( name ),
+ purchaser:purchaser_id ( name )
+ ''')
+ .execute();
+ ```
+ - 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).
+ dart: |
+ ```dart
+ final res = await supabase
+ .from('cities')
+ .select('name')
+ .execute(count: CountOption.exact);
+
+ final count = res.count;
+ ```
+ - 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.
+ dart: |
+ ```dart
+ final res = await supabase
+ .from('users')
+ .select('''
+ id, name,
+ address->street
+ ''')
+ .eq('address->postcode', 90210)
+ .execute();
+ ```
+ - 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.
+ dart: |
+ ```dart
+ fianl res = await supabase
+ .from('users')
+ .select()
+ .csv()
+ .execute();
+ ```
+
+ insert():
+ title: 'Create data: 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:
+ - name: Create a record
+ isSpotlight: true
+ dart: |
+ ```dart
+ final res = await supabase
+ .from('cities')
+ .insert([
+ {'name': 'The Shire', 'country_id': 554}
+ ]).execute();
+ ```
+ - name: Bulk create
+ dart: |
+ ```dart
+ final res = await supabase
+ .from('cities')
+ .insert([
+ {'name': 'The Shire', 'country_id': 554},
+ {'name': 'Rohan', 'country_id': 555},
+ ]).execute();
+ ```
+
+ update():
+ title: 'Modify data: update()'
+ notes: |
+ TODO update the link to dart
+ - `update()` should always be combined with [Filters](/docs/reference/javascript/using-filters) to target the item(s) you wish to update.
+ examples:
+ - name: Updating your data
+ isSpotlight: true
+ dart: |
+ ```dart
+ final res = await supabase
+ .from('cities')
+ .update({ 'name': 'Middle Earth' })
+ .match({ 'name': 'Auckland' })
+ .execute();
+ ```
+ - 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.
+ dart: |
+ ```dart
+ final res = await supabase
+ .from('users')
+ .update({
+ 'address': {
+ 'street': 'Melrose Place',
+ 'postcode': 90210
+ }
+ })
+ .eq('address->postcode', 90210)
+ .execute();
+ ```
+
+ upsert():
+ title: 'Upsert data: upsert()'
+ notes: |
+ - Primary keys should to 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:
+ - name: Upsert your data
+ isSpotlight: true
+ dart: |
+ ```dart
+ final res = await supabase
+ .from('messages')
+ .upsert({ 'id': 3, 'message': 'foo', 'username': 'supabot' })
+ .execute();
+ ```
+ - 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
+ dart: |
+ ```dart
+ final res = await supabase
+ .from('users')
+ .upsert({ 'username': 'supabot' }, { 'onConflict': 'username' })
+ .execute();
+ ```
+ - name: Return the exact number of rows
+ description: |
+ Allowed values for count option are `exact`, `planned` and `estimated`.
+ dart: |
+ ```dart
+ final res = await supabase
+ .from('users')
+ .upsert({
+ 'id': 3,
+ 'message': 'foo',
+ 'username': 'supabot'
+ })
+ .execute(count: CountOption.exact);
+ ```
+
+ delete():
+ title: 'Delete data: delete()'
+ notes: |
+ TODO update link to dart
+ - `delete()` should always be combined with [Filters](/docs/reference/javascript/using-filters) to target the item(s) you wish to delete.
+ examples:
+ - name: Delete records
+ isSpotlight: true
+ dart: |
+ ```dart
+ final res = await supabase
+ .from('cities')
+ .delete()
+ .match({ 'id': 666 })
+ .execute();
+ ```
+
+ 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:
+ - name: Call a stored procedure
+ isSpotlight: true
+ description: This is an example invoking a stored procedure.
+ dart: |
+ ```dart
+ final res = await supabase
+ .rpc('hello_world')
+ .execute();
+ ```
+ - name: With Parameters
+ dart: |
+ ```dart
+ final res = await supabase
+ .rpc('echo_city', params: { 'name': 'The Shire' })
+ .execute();
+ ```
+ - name: With count option
+ description: |
+ You can specify a count option to get the row count along with your data.
+ Allowed values for count option are `exact`, `planned` and `estimated`.
+ dart: |
+ ```dart
+ final res = await supabase
+ .rpc('hello_world')
+ .execute(count: CountOption.exact);
+ ```